简体   繁体   中英

WPF ListBox selection not grayed out when losing focus

I want to visualize a listbox item highlighted when selected, regardless the focus of the parent listbox.

在此处输入图片说明

In this example I have two listboxes. In both listboxes the first (and only) element is selected. ListBox 1 does NOT have Focus. ListBox 2 does have focus. I want to have identical highlighting color.

How do I achieve this in a custom listbox / listboxitem style?

Found the answer myself in Blend.

    <SolidColorBrush x:Key="Item.SelectedInactive.Background" Color="#3D26A0DA"/>
    <SolidColorBrush x:Key="Item.SelectedInactive.Border" Color="#FF26A0DA"/>
    <SolidColorBrush x:Key="Item.SelectedActive.Background" Color="#3D26A0DA"/>
    <SolidColorBrush x:Key="Item.SelectedActive.Border" Color="#FF26A0DA"/>

I now use the same borders and backgrounds (active / inactive).

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