I would like to customize the default – “OnMouseOver”-“color” for the Combobox and also the “Background” color for the list that drops down in the combobox ..can we customize the above mentioned properties of combobox..If yes, please help me..
the following is my Xaml code for the combobox :
<ComboBox Name="CmbBox1" BorderBrush="Black" Margin="1,1,1,1"
ItemsSource="{Binding}">
<ComboBox.Style>
<Style TargetType="{x:Type ComboBox}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Background="{Binding Background}" Foreground="Black" FontSize="10" TextAlignment="Left"
FontWeight="Black" Text="{Binding}"></TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Here is one way to do what I think you’re after. I made a few changes to your
ComboBox.Added comments in the Xaml code so it should be pretty self explanatory
Edit. This didn’t work under Windows 7 because of the
ButtonChromethat is deep within theComboBoxTemplate. You could either re-template the whole thing, or use this workaround which uses some code behind.First, add a reference to PresentationFramework.Aero
Then subscribe to the
Loadedevent of theComboBoxand disable theButtonChromeand bind the MainGrid background in the event handler like thisXaml