Today a simple record of a knowledge point: WPF Custom Window base class, common WinForm people know that WinForm form inheritance is very useful, write a basic form, directly in the background code rewrite the inherited form name. But if WPF is to inherit forms, I personally feel that I do not understand before: it is difficult, do not know how to deal with or can not inherit, but after understanding is very simple.
The first time you try to use WPF to directly modify background code to inherit a custom form sewindow you will get an error as follows:
Then the foreground code of the root tag changed from <Window></Window> to <<local:sewindow ></local:sewindow; thought, this can be compiled by the bar, After the front office has updated the code or not, and get another compilation error:
After a period of time to view WPF-related data, you can create a custom window base class that inherits from the window base class as follows. The steps are as follows:
First, create a base class for window
Add a class named Sewindow, the Window class introduces the System.Windows namespace, the Close event, the double-click event, and the time and method to maximize and restore events that may have overloaded versions are identified with the virtual keyword.
Second, use the base 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 foreground interface. xaml file, you need to modify the Manualactivationdialog. xaml, and change the root "window" into its own definition of the Sewindow modifications 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>
The compilation goes through!
WPF self-Learning Primer (ix) WPF Custom window base class