2
我現在正在使用TreeView。正如你可以看到CurrentMediumObjectives
和ChildrenObjective
是相同的對象類型,稱爲Objective
。如何在樹視圖中設置不同的樣式控制級別1和2?
這類有一個叫做Level
屬性,在ChildrenObjective
其中被設置爲1和ChildrenObjective
被設置爲2
我想設置不同DataTemplate
取決於Level
。
<TreeView ItemsSource="{Binding CurrentMediumObjectives}"
Margin="0,40,0,0">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding ChildrenObjective}">
<TextBlock FontWeight="Bold">
<Run Text="Objective " />
<Run Text="{Binding Level}" />
</TextBlock>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
我很困惑如果應該使用DataTemplateSelector或DataTrigger。 在此先感謝。
增加的更好的例子:) –
感謝。你的回答幫助了我很多! :) –