Windows inherited by WPF

Source: Internet
Author: User

Windows inherited by WPF are not as easy as winform and Asp.net

Assume that the parent window class we have written is basewindow, which corresponds to basewindow. CS and basewindow. in XAML, the window to inherit from is window1, corresponding to window1.cs and window1.xaml. The common action we perform is to use vs as the following statement in the automatically generated code:

Public partial class window1: Window

Modify:

Public partial class window1: basewindow

However, after compilation, you will get an error: window1 has different base classes.

This is because in window1.xaml


<Window
Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
X: class = "inheritwindowdemo. window1"
Width = "300" Height = "300">
<Grid X: Name = "layoutroot"/>
</WINDOW>

 

Our window inherits the window class and opens window1.g. CS can also see this (this is an intermediate file automatically generated by vs. You can "go to definition" on the initializecomponent () method of window1 to jump to this file, you can also find it in the OBJ "DEBUG directory ). This makes window1 inherit both the window and basewindow classes. Multi-inheritance is not allowed.

Naturally, you need to modify window1.xaml to change the root "window" to our basewindow:

  


<SRC: basewindow xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
X: class = "inheritwindowdemo. window1"
Xmlns: src = "CLR-namespace: inheritwindowdemo"
Height = "300"
Width = "300">
<Grid>
</GRID>
</Src: basewindow>

 

I thought, you can compile it now. Sorry, no, but I got another compilation error: SRC: basewindow cannot be the root of the XAML file, because it is defined by XAML, currently, the solution I want to avoid this problem is to make basewindow defined only in C # (that is, there is no basewindow. XAML, only basewindow. CS ).

 

 

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.