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