Bring element forward (Z Index) in Silverlight/WPF

前端 未结 7 1619
有刺的猬
有刺的猬 2020-12-04 19:42

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 i

7条回答
  •  有刺的猬
    2020-12-04 20:16

    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:

    interface IOrderable
        {
            int theZOrder{get;set;}
        }
    

    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:

    ItemsCont.ItemsSource = 
                ItemsCont.Items.OrderByDesc(t=>((IOrderable)t).theZOrder);
    

提交回复
热议问题