I have the code:
<ListBox Style="{StaticResource DeviceListBox}"
ItemsSource="{Binding MeterList, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
SelectedItem="{Binding CurrentMeter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
ItemContainerStyleSelector="{StaticResource DeviceListItemStyleSelector}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource DeviceListText}" Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
I use ItemContainerStyleSelector="{StaticResource DeviceListItemStyleSelector}" to change background color in each listbox items (e.g. black or silver, see – http://msdn.microsoft.com/en-us/library/system.windows.controls.styleselector.aspx). And it works. But if I add ItemContainerStyle="{StaticResource DeviceListItemStyle}" to create some triggers etc in DeviceListItemStyle then DeviceListItemStyleSelector doesn’t work. Help me, please!)
The
ItemContainerStyleSelectorselects a Style based on some logic, so obviously setting the Style manually will overwrite whatever Style your Selector applied.Why don’t you just set the background color in your
ItemContainerStyle?