Как связать с ListBox
ItemTemplate
правильно в приведенном ниже примере. Я хочу показать каждый ListBoxItem
, чтобы он отображался на цвет фона, указанный в теге.Переплет ListBox из ItemTemplate
<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>
Когда я применяю тему, это не работает. Но корректировка then ItemContainerStyle он работает/отменяет стиль темы. – Nuts