Note that there are some explanatory texts on larger screens.

plurals
  1. POOverride Selected Item in Combobox's style to show comboxbox's background not gray background
    primarykey
    data
    text
    <p>I am having an issue with getting a custom property set with a combobox. I am using .Net 4.0, WPF with xaml resources for types set in a dictionary and some brushes set in the app.xaml. I can get the nice rounded corner just find and a gradient and layout to my combobox using the surrounding 'border' trick. However I can't seem to get the 'Selected Item' in the combobox to have a background other than dull gray. I would prefer to change it to transparent and inherit the gradient of the parent border. However I am missing the property or relationship to do this.</p> <p>Does anyone know how to do this in the xaml? </p> <p>Image:</p> <p><img src="https://i.stack.imgur.com/EXAgj.jpg" alt="Combobox Current showings of Selections and selected"></p> <p>code:</p> <p>Dictionary item:</p> <pre><code> &lt;Style TargetType="{x:Type Border}"&gt; &lt;Setter Property="Background" Value="{StaticResource MoneyBrush}" /&gt; &lt;Setter Property="BorderBrush" Value="#071C07" /&gt; &lt;Setter Property="BorderThickness" Value="3" /&gt; &lt;Setter Property="CornerRadius" Value="20" /&gt; &lt;Setter Property="SnapsToDevicePixels" Value="True" /&gt; &lt;/Style&gt; </code></pre> <p>Brush in main App.xaml:</p> <pre><code>&lt;LinearGradientBrush x:Key="MoneyBrush" EndPoint="0.5,1" StartPoint="0.5,0"&gt; &lt;GradientStop Color="#3A883A" Offset="1" /&gt; &lt;GradientStop Color="#FFFFFF" Offset="0" /&gt; &lt;GradientStop Color="#FF53AA75" Offset="0.50" /&gt; &lt;GradientStop Color="#073307" Offset="0.95" /&gt; &lt;/LinearGradientBrush&gt; &lt;LinearGradientBrush x:Key="FontBrush" EndPoint="0.5,1" StartPoint="0.5,0"&gt; &lt;GradientStop Color="Black" Offset="0" /&gt; &lt;GradientStop Color="#107810" Offset="0.50" /&gt; &lt;GradientStop Color="Black" Offset="0.65" /&gt; &lt;/LinearGradientBrush&gt; </code></pre> <p>Actual item in mainwindow:</p> <pre><code>&lt;Border Margin="5" &gt; &lt;ComboBox Height="30" Width="170" Margin="10" x:Name="combopersons" FontSize="20" ItemsSource="{Binding Path=People}" DisplayMemberPath="FirstName" SelectedValuePath="PersonId" SelectedValue="{Binding Path=CurrentUser}" Foreground="{StaticResource FontBrush}"&gt; &lt;/ComboBox&gt; &lt;/Border&gt; </code></pre> <hr> <p>EDIT >>></p> <p>I like the solution proposed by @iltzortz, but I wanted a gradient so in this case this would work better:</p> <pre><code>&lt;ComboBox.Resources&gt; &lt;LinearGradientBrush x:Key="{x:Static SystemColors.WindowBrushKey}" &gt; &lt;GradientStop Color="#3A883A" Offset="1" /&gt; &lt;GradientStop Color="#FFFFFF" Offset="0" /&gt; &lt;GradientStop Color="#FF53AA75" Offset="0.50" /&gt; &lt;GradientStop Color="#073307" Offset="0.95" /&gt; &lt;/LinearGradientBrush&gt; &lt;LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" &gt; &lt;GradientStop Color="#000000" Offset="1" /&gt; &lt;GradientStop Color="#FFFFFF" Offset="0" /&gt; &lt;/LinearGradientBrush&gt; &lt;/ComboBox.Resources&gt; </code></pre> <p>EDIT 2 >>> </p> <p>For some reason this will only work on applications I have built using .NET 4.0 or higher on Visual Studio 2012 with Windows 7. When I try to run the code at home for some reason it won't render I believe this is due to either Windows 8 or Visual Studio 2010 interpreting different colors for different system values. Be aware of this if you have Windows 8 or Visual Studio 2010 as it will work for me for one environment but not the other... curious.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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