WPF (9) WPF custom window base class, wpf window

Source: Internet
Author: User

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!

Related Article

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.