Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling SelectedItem in ListView in Metro App XAML

I am having troubles setting up the style of selected item in metro app list box.

I have created the DataTemplate for the item in which there is a TextBlock which colour I would like to change. I tried many things from WPF but they are not available for metro like DataTemplate.Triggers, Style.Triggers and so on. I also tried to make a copy of the ItemContainerStyle template but since it uses ContentPresenter to display my DataTemplate I didn't know what to change to achieve what I want. The same was with value converter as I didn't know how to use RelativeSource to supply the converter with the IsSelected property of the ListBoxItem....

Thanks for help!

like image 614
zveljkovic Avatar asked Aug 27 '12 22:08

zveljkovic


1 Answers

You're exactly right to change the ItemContainerStyle. If you're in Visual Studio or Blend, right click on the ListView and select

Edit Additional Templates -> Edit Generated Item Container [ItemContainerStyle] -> Edit a Copy

It's important when doing this that 'Edit Current' is not enabled. If it is, find that template and delete it (it might be an empty template and you want the full template).

This will create a style for a ListViewItem. The ListViewItem has a lot of controls within it and most of them deal with Selection or other states. You'll want to make changes to the Selected VisualState.

like image 140
Shawn Kendrot Avatar answered Oct 21 '22 12:10

Shawn Kendrot