-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Describe the bug
When creating Live tile content via TileContentBuilder, I always get NullReferenceException when setting the text on Wide sized tile.
❗ This only happens when trying to create Wide Live tile alone ❗ When Medium tile is present, it's all working.
- Is this bug a regression in the toolkit?
No, it's a bug on the current version as well as in the current repository code.
Steps to Reproduce
- Can this be reproduced in the Sample App?
No, because in the sample app you're creating Live tile content for all sizes: Medium, Wide, and Large, this only happens when you want to set solely Wide Live tile content.
Create sample Live tile content with TileContentBuilder, but only for Wide tile size, like in the sample code below and try to run it:
var builder = new TileContentBuilder();
builder.AddTile(TileSize.Wide)
.SetTextStacking(TileTextStacking.Top)
.AddText("Header", hintStyle: AdaptiveTextStyle.Base)
.AddText("Subtitle", hintStyle: AdaptiveTextStyle.CaptionSubtle)
.SetBranding(TileBranding.NameAndLogo);
TileUpdateManager.CreateTileUpdaterForApplication().Update(new TileNotification(builder.Content.GetXml()));
Expected behavior
Screenshots
Bug in code
According to NullReferenceException, the core issue was thrown from this method:
TileContentBuilder.AddAdaptiveTileVisualChild(ITileBindingContentAdaptiveChild child, TileSize size)
After inspecting the code of that method in this repository, I think I found what's causing it.
It's this line in the method, it's incorrectly getting the content from MediumTile instead of WideTile. As MediumTile is not set in my case, the exception is thrown.
if (size.HasFlag(TileSize.Wide) && WideTile != null && GetAdaptiveTileContent(--> MediumTile <--) != null)
{
GetAdaptiveTileContent(WideTile).Children.Add(child);
}
Environment
NuGet Package(s): Microsoft.Toolkit.Uwp.Notifications
Package Version(s): 7.0.1
Windows 10 Build Number:
- Fall Creators Update (16299)
- April 2018 Update (17134)
- October 2018 Update (17763)
- May 2019 Update (18362)
- May 2020 Update (19041)
- October 2020 Update (19042)
- Insider Build (build number: )
App min and target version:
- Fall Creators Update (16299)
- April 2018 Update (17134)
- October 2018 Update (17763) -- MIN
- May 2019 Update (18362)
- May 2020 Update (19041) -- TARGET
- Insider Build (xxxxx)
Device form factor:
- Desktop
- Xbox
- Surface Hub
- IoT
Visual Studio
- 2017 (version: )
- 2019 (version: 16.9.4)
- 2019 Preview (version: )