简体   繁体   中英

WPF ListBox change onMouseOver and SelectedItem color

I have created a simple WPF form and added a listbox with some items on it. By default when i run the application on Windows 10 the mouseover effect is blue (the listitems background color changes) and for the selected item the same.

How can i change this color for mousover and selected item to lets say red ?

You can change the styles of Listbox directly (which Ayyappann's comment refers to). Another way you can change the highlight color, if you would like it to be global, is to change the system colors. So in your App.xaml you could put something like this:

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

I prefer this way if i want certain actions to stay consistent (mouse over any object), OR if i would like to allow styles to be changed dynamically. I will customize the individual styles of local objects if i am looking for that object to have a typical behavior. A list of the system colors can be found Here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM