All the documentation and examples I'm finding online for setting Z-Index to bring an element forward in Silverlight are using a Canvas element as a container.
My items are Border elements inside of an ItemsControl container in a DataTemplate. I'm using the MouseEnter and MouseLeave events to trigger an animation on the ScaleTransform.ScaleX and ScaleTransform.ScaleY so they grow when hovered. As they're resized and occupying the same space as other items in the container(s), the most recently added items are overlapping the older items (as opposed to the currently resizing item). Is there a CLEAN way to bring the current item forward in code where I trigger my animation so that they overlap all other items when they're resized?
Html works the same way. All the list items must be siblings if you want to lay them out in layers.
I extended the code above so that it will stop if it finds (for example) an ItemsPresenter. If the ContentPresenter doesn't show itself between here and the ItemsPresenter, then fall back on my original code.
For a control that uses the Grid as LayoutRoot you can just do something as simple as that within a control itself:
set zIndex of your element in this way
First find the Maximum ZIndex of all its child elements and then set the new ZIndex.
Then assign
First, the attached property Zindex is defined in Canvas and thus is not available in other derivatives of Panel.
The ItemsControl orders the subelements according to the order of the list. The first Item at the bottom of the stack and the last on top. With that given, all you have to do is making sure the selected item is on bottom of the list.
First create an interface for the ordering. Like this:
Now implement this in the class you're showing.
When you want to bring a item to the front, give it a high number and give all others a low number.
Al there's left is the actual ordering. Add something like this and you're set:
In WPF there is the Panel.ZIndex property that you can set in a trigger:
In the
Style
forContentPresenter
we set thePanel.ZIndex
to 99999 whenIsMouseOver
istrue
. It must be on theContentPresenter
and not theBorder
because theContentPresenter
s are children of theItemsControl
's panel.Unfortunately I don't think this property has made it to Silverlight yet...