Can WPF bind to a generic class I created?
It is basically Class<T> where T:MyInterface
Can I Bind to Class<T> and use MyInterface to Bind It?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
WPF can bind to any CLR object (or COM object exposed via the CLR), including instances of generic classes. The object can optionally implement INotifyPropertyChanged or subclass DependencyObject so that changes to its properties will be detected by the binding. If not, the property value is copied once when the binding is evaluated, but not updated.
Technically WPF does not “bind to a class”: It binds to an object which is an instance of that class. So taken literally the answer to your question would be “no,” but I assume you were asking if it could bind to an instance of a generic class in which case the answer is “yes.”
WPF does have a limitation as regarding generic classes: The XAML parser cannot create instances of generic classes or reference them within an
{x:Type }markup extension, so for most uses with XAML you must create a concrete subclass of your generic class and reference that in your XAML. The exception to this is that the outermost element in a XAML can use thex:TypeArgumentsattribute to specify a generic class.