本文介绍了如何在XAML中扩展WPF页面类以及后面的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个XAML页面",我想将它们的共同方面整合到我称为ACPage的Page类扩展中.尽管我认为我已经很接近了,但我必须缺少一些必不可少的知识.有人可以告诉我我想念什么吗?我正在寻找有关此(相当基本)主题的文章,但没有找到.

我收到以下警告:

警告1"Al_Cr.PageWelcome.InitializeComponent()"隐藏了继承的成员"Al_Cr.ACPage.InitializeComponent()".如果要隐藏,请使用new关键字. D:\ Projects \ Al Cr \ Al Cr \ Al Cr \ obj \ x86 \ Release \ PageWelcome.g.cs 50 21 Al Cr

这个错误:

错误2"Al_Cr.ACPage"不能是XAML文件的根目录,因为它是使用XAML定义的.第1行的位置15.D:\ Projects \ Al Cr \ Al Cr \ Al Cr \ PageWelcome.xaml 1 15 Al Cr

警告指向自动生成的PageWelcome.InitializeComponent()函数定义.错误指向下面的<big>local:ACPage</big>的末尾.

我的ACPage.xaml& ACPage.xaml.cs的定义如下:

I have several XAML "Page"s for which I would like to pull the facets that are in common together into a Page class extension I am calling ACPage. I must be missing some essential piece of knowledge, although I think I am pretty close. Can someone tell me what I am missing? I looked for an article on this (rather basic) topic, but didn''t find one.

I get the following warning:

Warning 1 ''Al_Cr.PageWelcome.InitializeComponent()'' hides inherited member ''Al_Cr.ACPage.InitializeComponent()''. Use the new keyword if hiding was intended. D:\Projects\Al Cr\Al Cr\Al Cr\obj\x86\Release\PageWelcome.g.cs 50 21 Al Cr

and this error:

Error 2 ''Al_Cr.ACPage'' cannot be the root of a XAML file because it was defined using XAML. Line 1 Position 15. D:\Projects\Al Cr\Al Cr\Al Cr\PageWelcome.xaml 1 15 Al Cr

The warning points to the auto-generated PageWelcome.InitializeComponent() function definition. The error points to the end of the <big>local:ACPage</big>, below.

My ACPage.xaml & ACPage.xaml.cs are defined thusly:

<Page x:Class="Al_Cr.ACPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      Style="{StaticResource StylePage}">
</Page>





public partial class ACPage : Page {
    public ACPage() {
    }
}



我的PageWelcome.xaml&因此,定义了ACPage的子类PageWelcome.xaml.cs:



My PageWelcome.xaml & PageWelcome.xaml.cs which is a subclass of ACPage are defined thusly:

<<big>local:ACPage</big> x:Class="Al_Cr.PageWelcome"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:local="clr-namespace:Al_Cr" >
    <Canvas>
         ...Welcome page stuff...
    </Canvas>
</local:ACPage>





public partial class PageWelcome : ACPage {
     public PageWelcome() {
         InitializeComponent();
     }
}



我正在使用MS Visual Studio C#2010 Express(版本10.0.30319.1)和.NET 4.0.30319.



I am using MS Visual Studio C# 2010 Express (Version 10.0.30319.1) and .NET 4.0.30319.

Thank you in advance!

推荐答案




这篇关于如何在XAML中扩展WPF页面类以及后面的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 06:56