2011-10-04 59 views
1

自定义WPF Page类我想创建一个自定义WPF页类,我的所有网页的派生自:使用并宣布在XAML

public class CustomPage : Page 
{ 
    // custom dependency props here... 
} 

我不明白怎么然后创建一个新的页面在我的Visual Studio项目中,然后让它使用自定义页面类型。问题是Page的XAML中的根元素。我如何申报?这是行不通的:

<local:CustomPage 
    xmlns:local="clr-namespace:MyProject" 
    x:Class="KinectLevelUp.CustomSwipe.Views.Page1" 
    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"> 

    <Grid> 
    <!-- page content here... --> 
    </Grid> 

</local:CustomPage> 

我相信我只是不明白如何限定在根元素级的CustomPage类型。

+0

你会得到什么错误? – SLaks

回答

2

您需要更改代码隐藏文件以继承CustomPage

+0

我已经这样做了,但是会导致以下编译错误:'MyProject.Page1'的部分声明不能指定不同的基类。自动生成的Page1.g.cs文件与我后面的代码冲突。 – kindohm

+0

您在XAML中遇到任何错误吗? – SLaks

+0

我的歉意 - 你是对的。我尝试了一些混合顺序的不同的东西。你的解决方案是对的。 – kindohm