Customizing selection in a Selector control
Controls deriving from Selector such as ListBox
and CombobBox
have rich template support with the ItemTemplate
property. There is no direct support, however, for customizing the way a selected item is rendered. At first, this seems easily fixable with a property trigger for the Selector.IsSelected
property; however, due to the way the default ListBoxItem
/ComboBoxItem
control template is designed, the result is suboptimal. Let's see how to customize selection rendering despite this inconvenience.
Getting ready
Run Visual Studio and open the CH08.DataTriggerDemo
project.
How to do it...
We'll customize the appearance of selection in the ListBox
used to show books with a fancy DataTemplate
:
Run the application as is. Click an item; it's back-filled with a blue color (the exact color depends on the Windows theme and any personalization that may have been made), causing a not-so-nice effect (for example, the author name becomes invisible for non-free books...