.net – WPF中的BringToFront

栏目: 编程工具 · 发布时间: 7年前

内容简介:http://stackoverflow.com/questions/5666754/bringtofront-in-wpf

我需要在WPF中引导一个自定义控件.

伪代码

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

我知道,我知道有一个ZIndex,但仍然不明白如何将简单的WinForm BringToFront替换为parent.SetZIndex(这个,MaxZIndex(parent)?1)?

也许在WPF这样一个很酷的事情中有更好的方法吗?

这是一个扩展函数,它将方法BringToFront功能添加到面板中包含的所有FrameworkElements中.
public static class FrameworkElementExt
  {
    public static void BringToFront(this FrameworkElement element)
    {
      if (element == null) return;

      Panel parent = element.Parent as Panel;
      if (parent == null) return;

      var maxZ = parent.Children.OfType<UIElement>()
        .Where(x => x != element)
        .Select(x => Panel.GetZIndex(x))
        .Max();
      Panel.SetZIndex(element, maxZ + 1);
    }
  }

http://stackoverflow.com/questions/5666754/bringtofront-in-wpf


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Text Algorithms

Text Algorithms

Maxime Crochemore、Wojciech Rytter / Oxford University Press / 1994

This much-needed book on the design of algorithms and data structures for text processing emphasizes both theoretical foundations and practical applications. It is intended to serve both as a textbook......一起来看看 《Text Algorithms》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码