Can you bind in XAML to a Class that takes a type T?
If I have a class myCLASS<T> and I want to bind a List<myClass<int>> to XAML can you do it?
Or do you have to write a wrapper class newMyClass: myClass<int> and then bind the XAML to newMyClass?
Thanks.
The WPF binding subsystem supports any type of object, structures, classes, generic classes and even dynamic objects. All that matters is that the instances have properties.
You cannot create generic classes in the resources of a typical WPF application because the object creation syntax does not support it. Nevertheless, objects that are created in code-behind, in your view-model, or by services (even if they are instances of generic types or nested generic types), can still participate in binding.
Here’s an example based on the question. Here’s some XAML for a window:
and here’s a generic class that resembles a
Pointclass:and here is some code-behind to support the binding in the XAML above:
and this is what it looks like:
We created instances of the generic class in the code-behind but bound to that data using XAML.