Inheriting a base window class in WPF
I have a couple of windows that use the same CloseWindow, MinimizeWindow, and WindowMouseDown functions that are implemented the same
This feels kind of a bad practice, so I tried implementing a base function for window that has all 3 of those functions and inheriting it in all of those windows
However it gave me a lot of problems in using the base Window functions (e.g. Show and Close) outside the class, and much more errors
Does anybody know a better way to address this problem?
This is the class I tried using as a base class:
6 Replies
What kind of errors do you encounter?
There is a window that wont allow me to inherit the class since the .g.i.cs file inherits System.Windows.Window and i cant change that
namespace Client {
Have you changed the XAML accordingly?
How so?
If your C# code inherits from anything other than
Window
you need to change it in XAML as well. The g.i.cs
is auto-generated.
I assume your C# class definition looks like
So your XAML need to look like this:
Got it, thanks