Click here to Skip to main content
15,850,103 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I learned that WPF doesn't support inheritance for classes created with XAML and the associated code behind. Is there a workaround? For instance, I have an app that is a WPF window that contains methods that I would like available in a derived class defined in a mixed mode assembly written in C++/CLI.

Anyone care to take a shot at a suggestion?

Thanks in advance
Updated 10-Nov-11 14:34pm

1 solution

As you already seem to know you have to separate the XAML from the code behind, you do that be creating a class like any other normal class and inherit from a Control, like Window then in order to alter the appearance and add stuff you have to create a Style.
The below article shows you how you can do it.
Building Custom Template-able WPF Controls[^]
Share this answer
alleyes 11-Nov-11 14:56pm    
Thanks for responding. I'm not sure if what you're suggesting solves the problem. The issue is not exactly visual inheritance. What I've tried is this: I defined a base class (no partials). I then in XAML create the control (a window in this case) derived from the base class. I target the window as a Class Library DLL so I can launch it from a C++ / CLI executable. The class is the C++ class derives from the base class also. At runtime I get the exception: The component 'MyInheritedForm' does not have a resource identified by the URI '/WPFNameSpce;component/mainwindow.xaml'.

I hope that is clearer.

Thanks again

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900