BringToFront in WPF

后端 未结 5 1040
小鲜肉
小鲜肉 2020-12-17 14:54

I need to bring to front a custom control in WPF.

pseudoCode

OnMouseDown()
{
    if (this.parent != null)
        this.parent.BringToFront(this);
}
<         


        
5条回答
  •  旧时难觅i
    2020-12-17 15:15

    I found better solution. Get it:

    foreach (var item in Grid1.Children)
    {
        if ((item as UIElement).Uid == "StackPan1")
        {
            UIElement tmp = item as UIElement;
            Grid1.Children.Remove(item as UIElement);
            Grid1.Children.Add(tmp);
            break;
        }
    }
    

    It is just example, not universal method. But you can use it in apps with dynamic adding of controls. This code just adds an element which you want to put on a top to the and of the UIElementCollection. It works if all of your elements have the same ZIndex.

提交回复
热议问题