Using generic types in Window.Resources

I am trying to use Generic Types in a Windows.Resources section in XAML code. To associate a notification for a collection of objects, my shared set inherits from an ObservableCollection, as shown below:

public class PresentationModalCollection<T> : ObservableCollection<T>
    {
        public PresentationModalCollection(List<T> list) : base(list)
        {

        }

    }  

There is an extension method that returns an ObservableCollection for a 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 PresentationModalCollection in my Window.Resources, as shown below:

<Window.Resources>
        <LearningWPF:PresentationModalCollection x:Key="customers">
            <LearningWPF:Customer FirstName="Mohammad" LastName="Azam" />
        </LearningWPF:PresentationModalCollection>


    </Window.Resources>

Of course, the code above does not work. Is there a way to do this without creating a CustomerCollection class that inherits from ObservableCollection?

+3
source share
1 answer

, . , CustomerCollection collection , , . Sacha Barber Generics XAML, -, , .

+2

Source: https://habr.com/ru/post/1711200/


All Articles