2011-08-09 151 views
3

我有一個頁面,其中包含一個可覆蓋的屬性「FileName」。 我想創建整個頁面,並從它們繼承來擁有相同的頁面但具有不同的文件名。繼承WPF頁面

這可能嗎?

主頁XAML:

<Page x:Class="Batcher_File" 
     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:my="clr-namespace:TB_InstallSystem" 
     DataContext="{Binding RelativeSource={RelativeSource Self}}" 
     mc:Ignorable="d" 
     d:DesignHeight="300" d:DesignWidth="600" 
     Title="Batcher"> 
    </Page> 

代碼隱藏:

Class Batcher_File 
    Private _fiBatch As New IO.FileInfo(TB.SystemMain.AppPath & "myfile.xml") 
    Public Overridable Property fiBatch As IO.FileInfo 
     Get 
      Return _fiBatch 
     End Get 
     Set(value As IO.FileInfo) 
      _fiBatch = value 
     End Set 
    End Property 
End Class 

第二頁XAML ??:

<!-- --> 

第二頁代碼隱藏:

Public Class Batc_After 
    Inherits Batcher_Filer 

    Private _fiBatch As New IO.FileInfo(TB.SystemMain.AppPath & "batch_after.xml") 
    Public Overrides Property fiBatch As IO.FileInfo 
     Get 
      Return _fiBatch 
     End Get 
     Set(value As IO.FileInfo) 
      _fiBatch = value 
     End Set 
    End Property 




End Class 

回答

1

當我在WPF中構建嚮導時,我正在做類似於此的事情。我這樣做的方式是創建一個類(比如說「MyPage」),它簡單地擴展了頁面併爲其添加了FileName屬性。然後,當您想要使用MyPage時,請在XAML中聲明它。這樣你的XAML將看起來像或多或少:

<mynamespace:MyPage 
    xmlns:mynamespace="clr-namespace:PathOfNamespace" 
    FileName="MyFileName.file"> 
    <some more XAML> 
</mynamespace:MyPage>