WPF (9) WPF custom window base class, wpf window
Today, we will briefly record a knowledge point: the WPF custom window base class, which is commonly known by winform users. winform inheritance is useful for writing a basic form, directly rewrite the inherited form name in the background code. However, if it is WPF that needs to inherit the form, I personally do not feel that it is difficult to understand before: Do not understand how to handle it or do not inherit; but after understanding it, it is very easy.
The first attempt to use WPF to directly modify the background code to inherit the custom form SEWindow will result in the following error:
Then, change the root mark of the front-end code from <Window> </Window> to <local: SEWindow> </local: SEWindow>. I thought, you can compile it now, after the code is updated in the front-end background, it still does not work, and another compilation error is returned:
After a period of viewing WPF related data, you can create a custom Window base class inherited from the Window base class as follows. The procedure is as follows:
1. Create a base class for Window
Add a class named SEWindow. The Window class introduces the System. Windows namespace, closes the event, double-click the event, and marks the time and method of the event to maximize and restore the event.
Ii. Use the basic class of Window
Create a window class, and change the background class to inherit the custom form base class.
Public partial class ManualActivationDialog: SEWindow
In the corresponding front-end interface. xaml file, you need to modify ManualActivationDialog. xaml and change the root "Window" to the custom SEWindow as follows:
<Local: SEWindow x: Class = "SEDWA. WPF. ManualActivationDialog"
Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
Xmlns: d = "http://schemas.microsoft.com/expression/blend/2008"
Xmlns: mc = "http://schemas.openxmlformats.org/markup-compatibility/2006"
Xmlns: local = "clr-namespace: SEDWA. WPF"
Mc: Ignorable = "d"
Title = "offline activation" Height = "165.517" Width = "490.517" WindowStartupLocation = "CenterScreen">
</Local: SEWindow>
Compilation successful!