WPF 图层管理
2011-08-31 10:59
141 查看
玩过phtoshop或者blend的人都知道里面都一个图层管理器,管理图层的遮挡顺序,有置顶层、置底层、置下一层、置上一层四个管理方式。
那么在wof中我们应该怎么玩呢? 请看代码,支持多个图层同时操作。
首先置顶:
置底类似:
置下一层:
置上一层:
那么在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; } } } } }
相关文章推荐
- WPF 图层管理
- cocos2d-x 多图层点击事件及管理相关问题记录
- WPF and Silverlight 学习笔记(九):WPF布局管理之Canvas、InkCanvas
- WPF案例之生产线控制器管理系统
- VisualNet网络资源地理分布图层管理
- FreeMicaps开发---图层管理
- 手机中安装CAD看图软件哪一款比较好用?而且还能进行图层管理?
- WPF库存管理系统界面(仿360UI风格)
- wpf控件样式管理示意图
- qgis 软件下载和图层管理和操作
- WPF案例之生产线控制器管理系统
- 基于ASP.NET WPF技术及MVP模式实战太平人寿客户管理项目开发(Repository模式)课程分享
- atitit.软件开发GUI 布局管理优缺点总结java swing wpf web html c++ qt php asp.net winform
- WPF and Silverlight 学习笔记(九):WPF布局管理之Canvas、InkCanvas
- 自已实现一个UI库-UI核心绘图层管理
- WPF案例之生产线控制器管理系统
- Caliburn笔记-元数据(Metadata)管理(wpf框架)
- Caliburn笔记-Presenter的管理(wpf框架)
- 基于ASP.NET WPF技术及MVP模式实战太平人寿客户管理项目开发视频教程
- 基于ArcGIS10.0和Oracle10g的空间数据管理平台八(C#开发)-图层分类标准定义