zoukankan      html  css  js  c++  java
  • WPF 图层管理

    玩过phtoshop或者blend的人都知道里面都一个图层管理器,管理图层的遮挡顺序,有置顶层、置底层、置下一层、置上一层四个管理方式。

    那么在wof中我们应该怎么玩呢? 请看代码,支持多个图层同时操作。

    首先置顶:

      private void BringToFront(List<UIElement> CurrentSelection ,UIElementCollection childrens)
            {
                List<UIElement> selectionSorted = (from item in CurrentSelection
                                                   orderby Canvas.GetZIndex(item as UIElement) ascending
                                                   select item as UIElement).ToList();
    
                List<UIElement> childrenSorted = (from UIElement item in childrens
                                                  orderby Canvas.GetZIndex(item as UIElement) ascending
                                                  select item as UIElement).ToList();
    
                int i = 0;
                int j = 0;
                foreach (UIElement item in childrenSorted)
                {
                    if (selectionSorted.Contains(item))
                    {
                        int idx = Canvas.GetZIndex(item);
                        Canvas.SetZIndex(item, childrenSorted.Count - selectionSorted.Count + j++);
                    }
                    else
                    {
                        Canvas.SetZIndex(item, i++);
                    }
                }
            }
    

    置底类似:

       private void SendToBack(List<UIElement> CurrentSelection ,UIElementCollection childrens)
    { List<UIElement> selectionSorted = (from item in CurrentSelection orderby Canvas.GetZIndex(item as UIElement) ascending select item as UIElement).ToList(); List<UIElement> childrenSorted = (from UIElement item in childrens
    orderby Canvas.GetZIndex(item as UIElement) ascending select item as UIElement).ToList(); int i = 0; int j = 0; foreach (UIElement item in childrenSorted) { if (selectionSorted.Contains(item)) { int idx = Canvas.GetZIndex(item); Canvas.SetZIndex(item, j++); } else { Canvas.SetZIndex(item, selectionSorted.Count + i++); } } }

     置下一层:

     private void SendBackward(List<UIElement> CurrentSelection ,UIElementCollection childrens)
            {
                List<UIElement> ordered = (from item in CurrentSelection
                                           orderby Canvas.GetZIndex(item as UIElement) ascending
                                           select item as UIElement).ToList();
    
                int count = childrens.Count;
    for (int i = 0; i < ordered.Count; i++) { int currentIndex = Canvas.GetZIndex(ordered[i]); int newIndex = Math.Max(i, currentIndex - 1); if (currentIndex != newIndex) { Canvas.SetZIndex(ordered[i], newIndex); IEnumerable<UIElement> it =childrens.OfType<UIElement>().Where(item => Canvas.GetZIndex(item) == newIndex);
    foreach (UIElement elm in it) { if (elm != ordered[i]) { Canvas.SetZIndex(elm, currentIndex); break; } } } } }

     置上一层:

      private void BringForward(List<UIElement> CurrentSelection ,UIElementCollection childrens)
            {
                List<UIElement> ordered = (from item in CurrentSelection
                                           orderby Canvas.GetZIndex(item as UIElement) descending
                                           select item as UIElement).ToList();
    
                int count = childrens.Count;
    for (int i = 0; i < ordered.Count; i++) { int currentIndex = Canvas.GetZIndex(ordered[i]); int newIndex = Math.Min(count - 1 - i, currentIndex + 1); if (currentIndex != newIndex) { Canvas.SetZIndex(ordered[i], newIndex); IEnumerable<UIElement> it = this.Children.OfType<UIElement>().Where(item => Canvas.GetZIndex(item) == newIndex); foreach (UIElement elm in it) { if (elm != ordered[i]) { Canvas.SetZIndex(elm, currentIndex); break; } } } } }

      

     

  • 相关阅读:
    OC和Swift中的UITabBar和UINaviGationBar的适配 [UITabbar在IPad中的适配]
    <iOS开发>之App上架流程(2017)
    iOS--LaunchImage启动页设置及问题解决
    去掉ambiguous expansion of macro警告
    iosapp开发者账号信息管理
    开发一个 app 有多难?
    Android SDK下载安装及配置教程
    抽象类和借口的区别
    array,vertor,arraylist,hashable,hashmap等几个易混淆概念的区别
    判断Set里的元素是否重复、==、equals、hashCode方法研究-代码演示
  • 原文地址:https://www.cnblogs.com/eboard/p/2160445.html
Copyright © 2011-2022 走看看