Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Naive Solution</strong>: Just add brush to the resources and reference it from the Background property (via StaticResource binding) of the ComboBox:</p> <pre><code>&lt;Window x:Class="WpfApplication2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"&gt; &lt;Window.Resources&gt; &lt;SolidColorBrush x:Key="BackgroundColorKey" Color="Red"/&gt; &lt;Style TargetType="{x:Type ComboBox}"&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsMouseOver" Value="True"&gt; &lt;Setter Property="Background" Value="{StaticResource BackgroundColorKey}" /&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;ComboBox Height="25"/&gt; &lt;/Grid&gt; </code></pre> <p> <strong>Problem</strong>: After item is selected the background color is reset back to the default color. The only solution to fix this is to override the default template of the combobox. </p> <p><strong>Fix</strong>: Modify default ComboBox template. ComboBox default template is present on msdn. Here is the link - <a href="http://msdn.microsoft.com/en-us/library/ms752094(v=vs.100).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms752094(v=vs.100).aspx</a>. See "ComboBox ControlTemplate Example" section.</p> <p>Related links:</p> <p><a href="https://stackoverflow.com/questions/250622/mouseover-highlighting-style-returning-to-default-after-a-second-caused-by-aero">MouseOver highlighting style returning to default after a second (Caused by Aero?)</a></p> <p><a href="http://social.msdn.microsoft.com/Forums/en/wpf/thread/a18891e9-8879-4819-9679-247341782f60" rel="nofollow noreferrer">http://social.msdn.microsoft.com/Forums/en/wpf/thread/a18891e9-8879-4819-9679-247341782f60</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload