【问题标题】:What is the format of the DataType property for a DataTemplate or HierarchicalDataTemplate in WPF?WPF 中 DataTemplate 或 HierarchicalDataTemplate 的 DataType 属性的格式是什么?
【发布时间】:2019-10-10 21:23:13
【问题描述】:

我试图了解 DataTemplate 或 HierarchicalDataTemplate 的 DataType 参数的格式。互联网上散布着很多示例,我可以复制并开始工作,但我不明白我的选择是什么。

例如:

<DataTemplate DataType="{x:Type model:DepartmentSelectionViewModel}">

我想了解 x:Type 的含义。以及什么模型:DepartmentSelectionViewModel 是什么意思。

或者:

<HierarchicalDataTemplate DataType="{x:Type r:NetworkViewModel}" ItemsSource="{Binding Children}">

同样,它有 x:Type。但这次是 r:NetworkViewModel。

其他示例将具有 sys: 或 local:。所有这些设置是什么意思?我怎样才能发现存在哪些其他设置? (设置甚至是描述它们的正确词吗?)

【问题讨论】:

    标签: wpf datatemplate


    【解决方案1】:

    modelr 指的是XAML namespace mappings

    这些通常在根标记或 XAML 文件中找到,并定义 CLR 命名空间,其中分别定义了类型(类)DepartmentSelectionViewModelNetworkViewModel

    <Window ... xmlns:model="clr-namespace:Project1" ... />
    

    namespace Project1
    {
        public class DepartmentSelectionViewModel { ... } 
    }
    

    您可以定义任意数量的命名空间映射。

    x:Type 是指将应用隐式DataTemplate 的类型,即DataType 属性设置为{x:Type model:DepartmentSelectionViewModel}DataTemplate 将应用于@987654334 中的所有DepartmentSelectionViewModel 对象视图渲染时TreeView 的@集合。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-12
      • 2011-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-16
      相关资源
      最近更新 更多