0
如何在以下示例中正确绑定ListBox
ItemTemplate
。我想将每个ListBoxItem
显示为在标签中指定的背景颜色。来自ItemTemplate的ListBox绑定
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Border Background="{Binding Path=Tag, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}">
<TextBlock Text="{Binding}"/>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.Items>
<ListBoxItem Content="1" Tag="Blue" />
<ListBoxItem Content="2" Tag="Green"/>
<ListBoxItem Content="3" Tag="Red"/>
</ListBox.Items>
</ListBox>
当我有一个主题应用上述不起作用仍然。但调整然后ItemContainerStyle 它工作/覆盖主题样式。 – Nuts 2014-09-29 03:27:04