【发布时间】:2009-04-14 15:02:27
【问题描述】:
我得到了一个TreeView,其中包含来自不同类的不同对象。现在我想构建一个属性面板,它显示不同的内容,取决于在TreeView 中选择的对象/类。构建此类面板的最佳方法是什么?不同的面板和折叠面板取决于选择(谁让我更容易实现 ObserverPattern?)?还是其他方法?
【问题讨论】:
标签: c# wpf visual-studio
我得到了一个TreeView,其中包含来自不同类的不同对象。现在我想构建一个属性面板,它显示不同的内容,取决于在TreeView 中选择的对象/类。构建此类面板的最佳方法是什么?不同的面板和折叠面板取决于选择(谁让我更容易实现 ObserverPattern?)?还是其他方法?
【问题讨论】:
标签: c# wpf visual-studio
我会将属性面板(可能只是一个ContentControl)绑定到TreeView 中的SelectedItem:
<ContentPanel Content="{Binding SelectedItem, ElementName=_treeView}"/>
然后我会使用DataTemplates 为您拥有的每类项目显示正确的面板:
<DataTemplate DataType="{x:Type local:SomeClass}">
<Label>This is displayed for SomeClass</Label>
</DataTemplate>
<DataTemplate DataType="{x:Type local:SomeOtherClass}">
<Label>This is displayed for SomeOtherClass</Label>
</DataTemplate>
显然,您的DataTemplates 可以根据需要复杂到显示TreeView 中存在的各种类。
【讨论】:
你的意思是property grid?
【讨论】: