Listbox ComboBox Highlight selected color

Today I’ve to customize the color of some controls part.
The easy way to customize the selected color of Listbox and ComboBox is to override the SystemColor resource.

Selected Item Background (listbox, combobox)

<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="White"/>

Selected Item Background not focused (listbox)

<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightBlue"/>    

Selected Item Foreground (listbox, combobox)

<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Red" />	

Selected Item Foreground not focused (listbox, combobox)

<SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="White" />	

This is the usual resources I use.
This link show all System Color
http://blogs.msdn.com/b/wpf/archive/2010/11/30/systemcolors-reference.aspx

This is the code to override the resource:

<ComboBox>
    <ComboBox.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="White"/>
    </ComboBox.Resources>
    ....

</ComboBox>

Or if we want to change it in a style to apply to many controls

<Style x:Key="ComboBoxRounded2LivelloStyle" TargetType="{x:Type ComboBox}">
    <Style.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="{StaticResource ForegroundGeneralColor}" />
	<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="{StaticResource ForegroundBox2LivelloColor}" />
    </Style.Resources>
</Style>
Annunci

Informazioni su Andrea Regoli

Project Manager .Net Developer WPF WP7 Asp.Net c# javascript ajax SQL sharepoint
Questa voce è stata pubblicata in Silverlight, WP7, WPF, xaml e contrassegnata con , , , , . Contrassegna il permalink.

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...