First, my scenario. I have a ViewModel with a public property Items of type ObservableCollection<UserControl> which contains UserControls that I want to display using <ItemsControl ItemsSource="{Binding Items}" />.
I get the UserControls using Application.Current.TryFindResource("ControlKey") as UserControl.
When every resource has a different x:Key, everything works fine. However, when I add more UserControls to Items with the same x:Key, the ItemsControl displays only one of the UserControls with identical x:Key even though all of the UserControls are present in Items.
In example, I add items to the collection like so:
Items.Add(Application.Current.TryFindResource("Filter1") as UserControl);
Items.Add(Application.Current.TryFindResource("Filter1") as UserControl);
Items.Add(Application.Current.TryFindResource("Filter2") as UserControl);
Only two controls show up in the ItemsControl, one with x:Key "Filter1" and the one with "Filter2". The second UserControl with x:Key "Filter1" is not shown.
What am I missing? Thanks a lot.