继承自WPF页面

3

我有一个页面,其中包含一个可重写的属性“FileName”。 我想创建整个页面并从中继承,以拥有相同的页面但具有不同的文件名。

这可能吗?

主页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个回答

1
当我在WPF中构建向导时,我正在做与此非常相似的事情。我所采取的方法是创建一个类(假设为“MyPage”),它仅扩展页面并将FileName属性添加到其中。然后,当您想要使用MyPage时,在XAML中声明它。这样,您的XAML看起来会更或多或少像:
<mynamespace:MyPage 
    xmlns:mynamespace="clr-namespace:PathOfNamespace"
    FileName="MyFileName.file">
    <some more XAML>
</mynamespace:MyPage>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接