I’m sure this is easy, but new to me for WPF using C#. I know about inheriting from classes and have done so many times such as in C# WinForms projects…
public class MyClass : DerivedFromClass
{}
However, stumped in WPF and here’s the issue. I want to build my own set of controls to be used as a baseline for a new learning project… preset my own styles, colors, backgrounds, and other functionality. No problem. Start first with a WPF Window and create “MyWindow”.
Now, I want to take this baseline “MyWindow” and subclass THAT for yet another class of MySubClassedWindow. So, I create a new Window class, and by default, VS2010 builds the both designer and code portions of the form. I do view code on the MySubClassedWindow and find
partial class MySubclassedWindow : Window
{}
In C# using WinForms, I would just change to (and I’ve included the class library reference that includes the “MyWindow” declaration.
partial class MySubclassedWindow : MyWindow
{}
When I do, I get a compilation error of
Partial declarations of 'MyNameSpace.MySubclassedWindow' must not specify different base classes
Your base class should just be a class file (not a
Window).So create WindowBase.cs
In MainWindow (for example) change the xaml.cs file to inherit from WindowBase instead
In MainWindow.xaml, include the namespace for WindowBase and change Window to base:WindowBase like this