I am trying to use Generic Types in Windows.Resources section in XAML code. To attach the notification for a collection of objects my generic collection inherits from ObservableCollection as shown below:
public class PresentationModalCollection<T> : ObservableCollection<T>
{
public PresentationModalCollection(List<T> list) : base(list)
{
}
}
There is an extension method that returns a ObservableCollection for List as shown below:
public static class ExtensionMethods
{
public static PresentationModalCollection<T> ToObservableCollection<T>(this List<T> list)
{
return new PresentationModalCollection<T>(list);
}
}
Now, I want to use the PresentationModalCollection in my Window.Resources like shown below:
<Window.Resources>
<LearningWPF:PresentationModalCollection x:Key="customers">
<LearningWPF:Customer FirstName="Mohammad" LastName="Azam" />
</LearningWPF:PresentationModalCollection>
</Window.Resources>
Of course, the above code does not work. Is there any way of doing the above without having to create a class CustomerCollection which inherits from the ObservableCollection?