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:

  1. Run the application ...

Get Windows Presentation Foundation 4.5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.