-
Notifications
You must be signed in to change notification settings - Fork 776
Description
Describe the bug
I have a bunch of view models (using MVVM Toolkit, so they implement INotifyPropertyChanged) that I want to display in a ContentControl with a DataTemplateSelector. My template selector overrides both SelectTemplateCore(object item) and SelectTemplateCore(object item, DependencyObject container), but item is always null. Using the exact same binding but without the template selector works as expected.
I have been able to repro this in several slightly different scenarios in my actual project, but copying the relevant code into a fresh project doesn't have the same issue.
Steps to reproduce the bug
- Clone https://github.com/yoshiask/FluentStore
- Look over the template selectors in use (they're both pretty much the same): https://github.com/yoshiask/FluentStore/blob/master/FluentStore/Controls/PackageDisplayTemplateSelector.cs, https://github.com/yoshiask/FluentStore/blob/master/FluentStore/Controls/ImageBaseTemplateSelector.cs
- Take a look at uses of
ContentControlwith a DataTemplateSelector: https://github.com/yoshiask/FluentStore/blob/master/FluentStore/Views/PackageView.xaml#L31, https://github.com/yoshiask/FluentStore/blob/master/FluentStore/Views/PackageView.xaml#L54, https://github.com/yoshiask/FluentStore/blob/master/FluentStore/Views/PackageView.xaml#L180 - Build and deploy the UWP project.
- On the home page, click on the "Free" button on any of the carousel items.
- Scroll down and observe that the ContentControl appears empty.
Expected behavior
The template selectors to be passed the values they are bound to.
Version Info
NuGet package version:
Microsoft.UI.Xaml 2.6.1
| Windows version | Saw the problem? |
|---|---|
| Insider Build (22000.120) | Yes |
| October 2020 Update (19042) | |
| May 2020 Update (19041) | |
| November 2019 Update (18363) | |
| May 2019 Update (18362) | |
| October 2018 Update (17763) | |
| April 2018 Update (17134) | |
| Fall Creators Update (16299) | |
| Creators Update (15063) |
| Device form factor | Saw the problem? |
|---|---|
| Desktop | Yes |
| Xbox | |
| Surface Hub | |
| IoT |
Additional context
Although my attempt at a minimum repro wasn't successful, here's the link to it:
https://github.com/yoshiask/Repros/tree/master/ContentControlTemplateSelector
I'm not really sure why it works here but not in the main project, but maybe it's still useful for pinning down the issue.
Also, here is a link to a discussion in the UWP Community Discord server, so you can see what I have tried so far:
https://discord.com/channels/372137812037730304/580484470877061120/873706002816585739
