Windows Phone 8.1. AppBarButton icon with two lines of text.
2 answers
The AppBarButton does not display any text or arbitrary Xaml in its icon. It must be a character from a font, bitmap, or path. For displaying a calendar like you, a bitmap would be best for you.
Since you probably don't want to create 366 icons, you can use RenderTargetBitmap to create them on the fly. Assuming "ButtonImageMaster" is Xaml snippet with day and month and calendarButton is AppBarButton:
RenderTargetBitmap rtb = new RenderTargetBitmap();
await rtb.RenderAsync(ButtonImageMaster);
IBuffer pixelBuffer = await rtb.GetPixelsAsync();
string fileName = "calIcon.png";
StorageFile calIconFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(fileName,CreationCollisionOption.ReplaceExisting);
using (IRandomAccessStream stream = await calIconFile.OpenAsync(FileAccessMode.ReadWrite))
{
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
encoder.SetPixelData(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Straight,
(uint)rtb.PixelWidth,
(uint)rtb.PixelHeight,
DisplayInformation.GetForCurrentView().LogicalDpi,
DisplayInformation.GetForCurrentView().LogicalDpi,
pixelBuffer.ToArray());
await encoder.FlushAsync();
}
BitmapIcon icon = new BitmapIcon();
icon.UriSource = new Uri("ms-appdata:///temp/"+fileName);
calendarButton.Icon = icon;
+2
source to share