我有一个 TreeView 元素,我试图从另一个程序集中定义的资源字典中设置它的 DataTemplates。我正在使用一种非常简单的方法:
<TreeView x:Name="treeView"
ItemsSource="{Binding Path=Vehicles}">
<TreeView.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/CarsLib;component/TreeTemplateDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</TreeView.Resources>
</TreeView>
然而。这似乎不起作用。我调试它并注意到 ResourceDictionary 已加载。请帮助我了解我错过了什么。资源字典看起来像这样:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CarsLib">
<HierarchicalDataTemplate x:Key="StationTreeViewTemplate"
DataType="{x:Type local:Station}"
ItemsSource="{Binding Path=FamounsModels}">
<DockPanel>
<TextBlock Text="{Binding Path=Name}" Margin="3,3,3,3" />
<TextBlock Text="{Binding Path=EngineSize}" Margin="3,3,3,3" />
</DockPanel>
</HierarchicalDataTemplate>
谢谢,
伊扎尔洛特姆