Bring element forward (Z Index) in Silverlight/WPF

前端 未结 7 1667
有刺的猬
有刺的猬 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:21

    set zIndex of your element in this way

    var zIndex = 
        ((Panel) element.Parent)
        .Children.Cast()
        .Max(child => Canvas.GetZIndex(child))
        ;
    
    zIndex++;
    
    Canvas.SetZIndex(element, zIndex);
    
    • maybe you need to check if zIndex is equal to int.MaxValue then reset "ZIndex"s.
    • but this almost never happens

提交回复
热议问题