1

I'm wanting to increase the size of a selected item in a ListBox and show extra controls. I'm not sure how the ListBoxItem template knows whether the item is selected or not. In the past I would wrap all of my items in radio buttons but it is very clunky and didn't utilize the ListBox selection at all. I would really like to have a better way. Ideally, I would like the change to be in a visual state so I can animate the transition.

Thanks.

Jordan
  • 9,642
  • 10
  • 71
  • 141
  • See this SO question. http://stackoverflow.com/questions/5771362/wpf-how-to-set-the-data-template-trigger-for-content-control, what you want to do is trigger on the `IsSelected` property. – CodingGorilla Jun 26 '12 at 17:13
  • @CodingGorilla, not really what I want. Looking for a way of animating a transition when an item is selected. – Jordan Jun 26 '12 at 19:22

1 Answers1

1

ListBoxItem already defines the visual states Selected and Unselected. See ListBox Styles and Templates for how the ControlTemplate in ListBoxItem's default style handles these states.

Clemens
  • 123,504
  • 12
  • 155
  • 268
  • I'm not sure how any of this information helps me. Could you give me some code? How is the visual state of the `ItemTemplate` changed based upon with the `ListBoxItem`'s `IsSelected` value. I guess I'm confused. – Jordan Jun 27 '12 at 19:45
  • Visual state changes are performed by the ListBoxItem. You don't have to change state in your code. Simply declare your own `` and `` in the ControlTemplate our your ListBoxItem Style and animate whatever you like. Take the ListBoxItem's default style as an example of how to declare VisualStates. – Clemens Jun 28 '12 at 07:08