Reputation: 981
I have a Silverlight project and I want to customize the appearance of ComboBox control, so I add a ResourceDictionary.xaml file, overwrite the default style of ComboBox, apply this new style to ComboBox, and it works fine.
<Style TargetType="ComboBox" x:Key="CommonComboBoxStyle">
<Setter Property = "xxx" Value="XXX" />
....
</Style>
Soon I realized that I also need to customize the appearance of ComboBoxItem, I want to change its background color when an item is selected/mouseovered, so I overwritten its default style:
<Style x:Key="FilterDownComboBoxItemContainerStyle" TargetType="ComboBoxItem">
.....
<Rectangle x:Name="fillColor" Fill="#FF0054A6" IsHitTestVisible="False" Opacity="0" RadiusY="0" RadiusX="0"/>
<Rectangle x:Name="fillColor2" Fill="#FF0054A6" IsHitTestVisible="False" Opacity="0" RadiusY="0" RadiusX="0"/>
</Style>
Here is the question, I want to put FilterDownComboBoxItemContainerStyle in CommonComboBoxStyle, so I just need to apply CommonComboBoxStyle to ComboBoxes that I want, no need to apply FilterDownComboBoxItemContainerStyle separately to every ComboBoxItem, are there any ways to set style of ComboBoxItem in ComboBox style?
Upvotes: 0
Views: 191
Reputation: 102723
are there any ways to set style of ComboBoxItem in ComboBox style?
Yes, you can use ComboBox.ItemContainerStyle
for this:
<Style TargetType="ComboBox" x:Key="CommonComboBoxStyle">
<Setter Property="ItemContainerStyle" Value="{StaticResource FilterDownComboBoxItemContainerStyle}" />
</Style>
Upvotes: 1