c# - 在 XAML 中使用 System.Type

标签 c# wpf types

我需要能够在 UserControl 中设置 System.Type 类型的属性。我目前正在这样做:

XAML:

<MyUserControl x:Name="TheControl"/>

代码隐藏:

TheControl.TheType = typeof(My.NameSpace.MyType);

我希望能够做到这一点(仅限 XAML):

<MyUserControl x:Name="TheControl" TheType="??"/>

有没有办法在 XAML 中使用 typeof

最佳答案

使用 x:Type Markup Extension :

<MyUserControl 
    xmlns:myns="clr-namespace:My.NameSpace"
    x:Name="TheControl"
    TheType="{x:Type myns:MyType}"/>

关于c# - 在 XAML 中使用 System.Type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3493241/

相关文章:

WPF DataGrid 全行选择

c# - 如何确定类型是否是 Action/Func 委托(delegate)之一?

arrays - 为什么 Swift 有时会将混合类型数组视为单一类型数组?

vb6 - Visual Basic 6.0 中的自动类型转换

c# - 路由事件 "the member is not recognized or is not accessible"

c# - 应用程序无法写入注册表,即使用户具有管理权限

c# - 在 MVC 3 中对 DataTable 对象使用分页

c# - 为什么委托(delegate)声明需要提及标识符?

wpf - 允许 WPF 网格单元格内容扩展到网格单元格之外?

c# - 从 VS 2010 扩展在代码编辑器中打开无文件源代码文档