Search code examples
c#uwptile

UWP Tile Image Stretch and Fill


I am trying to implement a tile with the a thumbnail completely covers the tile. But there is some margin. How can I remove that and make it stretch and fill the entire tile?

TileMedium

Another question is that, in addition to the image problem, in the TileMedium, the text is not showing up. I am expecting it to appear at the left bottom. How should I fix it?

TileWide

My last question is, although I have implemented it in the code, TileLarge doesn't appear as an option when I right click the tile to adjust its size.

This is the code:

    public static void UpdateTile(Music music)
    {
        string uri = Thumbnail.Path;
        var tileContent = new TileContent()
        {
            Visual = new TileVisual()
            {
                TileMedium = new TileBinding()
                {
                    Branding = TileBranding.None,
                    Content = new TileBindingContentAdaptive()
                    {
                        Children =
                        {
                            new AdaptiveImage() { Source = uri },
                        }
                    }
                },
                TileWide = new TileBinding()
                {
                    Branding = TileBranding.None,
                    Content = new TileBindingContentAdaptive()
                    {
                        Children =
                        {
                            new AdaptiveImage()
                            {
                                Source = uri
                            },
                            new AdaptiveText()
                            {
                                Text = music.Name,
                                HintStyle = AdaptiveTextStyle.Title
                            }
                        }
                    }
                },
                TileLarge = new TileBinding()
                {
                    Branding = TileBranding.None,
                    Content = new TileBindingContentAdaptive()
                    {
                        Children =
                        {
                            new AdaptiveImage()
                            {
                                Source = uri
                            },
                            new AdaptiveGroup()
                            {
                                Children =
                                {
                                    new AdaptiveSubgroup()
                                    {
                                        Children =
                                        {
                                            new AdaptiveText()
                                            {
                                                Text = music.Name,
                                                HintStyle = AdaptiveTextStyle.Caption
                                            },
                                            new AdaptiveText()
                                            {
                                                Text = music.Artist,
                                                HintStyle = AdaptiveTextStyle.CaptionSubtle
                                            }
                                        }
                                    }
                                }
                            },
                        }
                    }
                }
            }
        };

        // Create the tile notification
        var tileNotification = new TileNotification(tileContent.GetXml());

        // And send the notification to the primary tile
        tileUpdater.Update(tileNotification);
    }
}

Sorry for so many questions. Thanks in advance!


Solution

  • Q1:Image problem

    If you want to fill the tile,you can set the image to the BackgroundImage instead of AdaptiveImage.

    Q2:Show text at the left bottom in TileMedium.

    You can set Displayname and Branding in TileMedium.In this case,the text will appear at the left bottom.

    TileMedium = new TileBinding()
    {
        DisplayName = music.Name,
        Branding = TileBranding.Name,
        Content = new TileBindingContentAdaptive()
        {
            BackgroundImage = new TileBackgroundImage()
            {
                Source = uri
            },
            Children =
            {
                ......
            }
        }
    },
    

    Q3:TileLarge

    Go to Package.appxmanifest->Visual Assets->Large Tile.Select Large Tile option in Display Settings.