将XAML UserControl绑定到在运行时更改类型的对象

时间:2019-03-04 13:59:41

标签: wpf vb.net xaml inheritance binding

我有WPF项目。在应用程序中,我有类,表示特定的操作。操作类型由属性 Type 设置。例如:

Public Class Action
    Public Property Type as Types
End Class 

Dim act1 as new Action() With {.Type = Types.SendCommand}
Dim act2 as new Action() With {.Type = Types.SendFile}

此对象绑定到XAML用户控件。取决于对象的属性 Type 的值,用户控件可以更改其配置。例如。如果对象 act1 的属性类型为 Types.SendCommand ,则用户控件具有带有命令文本的字段。如果将 act1 的类型设置为 Types.SendFile ,则用户控件具有选择文件的按钮并使用命令隐藏字段。

现在我需要其他设计:像这样创建基类和子类:

Public MustInherit Class ActionBase
    Public MustOverride ReadOnly Property Type as Types
End Class

Public Class SendCommandAction Inherits ActionBase
    Public Overrides ReadOnly Property Type as Types = Types.SendCommand
    ... other specific properties
End Class

Public Class SendFileAction Inherits ActionBase
    Public Overrides ReadOnly Property Type as Types = Types.SendFile
    ... other specific properties
End Class

现在我需要将用户控件绑定到这个新对象。但是我不知道什么是正确的方法。因为此设计需要在运行时更改对象的类型。请给我提示如何在当前设计中解决此问题。

0 个答案:

没有答案
相关问题