WPF self-Learning Primer (ix) WPF Custom window base class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.