0

Is there a way to create a custom ShellTile that displays at start (after user pins our app)? I would like to resize and reposition a count number (label), but I can't find a way to do that.

sertsedat
  • 3,490
  • 1
  • 25
  • 45
paxx
  • 1,079
  • 2
  • 12
  • 26

1 Answers1

3

You can't change the position or style of title or counter, but you can generate an image to display on the tile, for example:

WriteableBitmap bitmap = new WriteableBitmap(173, 173);

TextBlock textBlock = new TextBlock();
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Foreground = new SolidColorBrush(Colors.White);
textBlock.FontSize = 22.0;
textBlock.Margin = new Thickness(12.0, 8.0, 8.0, 45.0);
textBlock.Text = "Lorem ipsum";
textBlock.HorizontalAlignment = HorizontalAlignment.Stretch;
textBlock.VerticalAlignment = VerticalAlignment.Stretch;

Grid layoutRoot = new Grid();
layoutRoot.Background = (Brush)App.Current.Resources["PhoneAccentBrush"];
layoutRoot.Width = 173.0;
layoutRoot.Height = 173.0;
layoutRoot.Children.Add(textBlock);

layoutRoot.Measure(new Size(173, 173));
layoutRoot.Arrange(new Rect(0, 0, 173, 173));
layoutRoot.UpdateLayout();
bitmap.Render(layoutRoot, null);
bitmap.Invalidate();

using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
    string fileName = "/Shared/ShellContent/BackgroundImage.jpg";
    using (Stream fileStream = storage.CreateFile(fileName))
    {
        bitmap.SaveJpeg(fileStream, 173, 173, 0, 100);
    }
}

StandardTileData tileData = new StandardTileData
{
    BackgroundImage = new Uri("isostore:"/Shared/ShellContent/BackgroundImage.jpg, UriKind.Absolute),
    Title = "Lorem Ipsum,
};

ShellTile.Create(new Uri("/MainPage.xaml", UriKind.Relative), tileData);
Loránd Biró
  • 856
  • 6
  • 7