Windows Phone 8.1. AppBarButton icon with two lines of text.

I would like to know how to make the AppBarButton Icon equal to 2 lines of text. I want to do it like in Windows Calendar:

image

+3


source to share


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


In WP 8.1 Silverlight, you can use a constructor WriteableBitmap(FrameworkElement element, Transform transform)

WriteableBitmap

(derived from ImageSource

) to generate a "screenshot of a memory-generated frame element". Then you can set it to bitmap icon.



0


source







All Articles