2011-10-04 41 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