I have a ListBox
that uses a WrapPanel
for its ItemsPanel
, a custom ItemTemplate
, and a custom ItemContainerStyle
. The ItemContainerStyle's template contains a selection box that shows up when an item is selected. The graphics designer would like this selection box to overlap sibling items in the ListBox like it's an overlay.
The first thing I tried was setting the Canvas.ZIndex
property of the ItemContainer in the Selected state. That did not seem to have an effect. Then I read that list items might be wrapped inside of a ContentPresenter
, so I created an attached property that changes the ZIndex of an item's parent, but then I found out Silverlight storyboards don't let you animate custom attached properties.
Does anyone know of a technique we can use to achieve the effect we desire?
I found a solution. Basically, I created an attached property that sets up an event handler on any
Selector
(includingListBox
) for when its selection changes. When it changes, the code iterates through all of the item containers, adjusting theCanvas.ZIndex
based on whether the container represents the selected item: