1.GetVisualParent

public static T GetVisualParent<T>(DependencyObject obj) where T : DependencyObject
{
DependencyObject parent = obj;
while (true)
{
if (parent == null) return null;
T t = parent as T;
if (t != null) return t;
parent = VisualTreeHelper.GetParent(parent);
}
}

使用示例代码:

Button btn = sender as Button;
ListViewItem item = Utilities.GetVisualParent<ListViewItem>(btn);

2.GetVisualChildren
1)方法:

public static ReadOnlyCollection<T> GetVisualChildren<T>(DependencyObject obj) where T : DependencyObject
{
List<T> list = new List<T>();
int count = VisualTreeHelper.GetChildrenCount(obj);
for (int i = ; i < count; i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child is T) list.Add((T)child);
list.AddRange(GetVisualChildren<T>(child));
}
return new ReadOnlyCollection<T>(list);
}

2)示例代码 Button btn = sender as Button;

ListViewItem item = Utilities.GetVisualParent<ListViewItem>(btn);
if (item == null) return;
ReadOnlyCollection<ComboBoxEdit> cbxCollection= Haitai.Common.Utilities.GetVisualChildren<ComboBoxEdit>(item);

Visual Tree的更多相关文章

  1. 2000条你应知的WPF小姿势 基础篇<45-50 Visual Tree&Logic Tree 附带两个小工具>

    在正文开始之前需要介绍一个人:Sean Sexton. 来自明尼苏达双城的软件工程师.最为出色的是他维护了两个博客:2,000Things You Should Know About C# 和 2,0 ...

  2. UWP开发入门(十二)——神器Live Visual Tree

    很久以前,我们就有Snoop这样的工具实时修改.查看正在运行的WPF程序,那时候调个样式,修改个模板,相当滋润.随着历史的车轮陷进WP的泥潭中,无论WP7的Silverlight还是WP8.1的run ...

  3. How to remove live visual tree?

    How to remove live visual tree? How to不显示实时可视化树 Remove the "Go to live visual tree" / &quo ...

  4. WPF中的Visual Tree和Logical Tree与路由事件

    1.Visual Tree和Logical TreeLogical Tree:逻辑树,WPF中用户界面有一个对象树构建而成,这棵树叫做逻辑树,元素的声明分层结构形成了所谓的逻辑树!!Visual Tr ...

  5. WPF知识点全攻略06- WPF逻辑树(Logical Tree)和可视树(Visual Tree)

    介绍概念之前,先来分析一段代码: xaml代码如下: <Window x:Class="WpfApp1.MainWindow" xmlns="http://sche ...

  6. WPF中Logical Tree和Visual Tree的区别

    The Logical TreeThe logical tree describes the relations between elements of the user interface. The ...

  7. WPF 中的逻辑树(Logical Tree)与可视化元素树(Visual Tree)

    一.前言 ​ WPF 中有两种"树":逻辑树(Logical Tree)和可视化元素树(Visual Tree). Logical Tree 最显著的特点就是它完全由布局组件和控件 ...

  8. Visual Studio 2015 CTP6 发布

    微软发布ASP.NET 5 支持在Windows.Mac和Linux上构建程序,Visual Studio 2015 CTP6(社区预览版)现已发布了.感兴趣的朋友们可以登录官网下载[http://w ...

  9. Visual Studio 2015速递(2)——提升效率和质量(VS2015核心竞争力)

    系列文章 Visual Studio 2015速递(1)——C#6.0新特性怎么用 Visual Studio 2015速递(2)——提升效率和质量(VS2015核心竞争力) Visual Studi ...

随机推荐

  1. 【SQL】181. Employees Earning More Than Their Managers

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  2. python语法(一)

    Python是一种面向对象.直译式电脑编程语言,也是一种功能强大的通用型语言,已经具有近二十年的发展历史,成熟且稳定.在近几年,大数据,人工智能火起来之后也是水涨船高,被越来越多的人知道,并且越来越多 ...

  3. 让screen帮助你协同工作

    Screen是系统管理员手中的一件利器,下面我把它介绍给你,相信你会和我一样,认可这个非常棒的软件 一,什么情况下会用到screen?   比如说,我们在运行一个非常费时间的程序,注意:可能我们是在通 ...

  4. [OpenGL]纹理贴图实现 总结

    实现步骤 第一步:设置所需要的OpenGL环境 设置上下文环境 删除已经存在的渲染的缓存 设置颜色缓存 设置帧缓存 清除缓存 设置窗口大小 开启功能 编译shander 使用program 获取sha ...

  5. python数据库操作——sqlite3模块

    # -*- coding: utf-8 -*- ''' Version : Python27 Author : Spring God Date : 2012-4-26 ''' import sqlit ...

  6. 客户端程序获取自己的ip、isp、地理位置等信息

    @ 比如说你需要收集用户信息,又或者要通过这些信息让用户登陆合适的服务器(北京联通用户登陆北京联通服务器). @ 淘宝和新浪都提供了类似的API,你只需要发送一个http请求,它就返回一个json格式 ...

  7. [置顶] 解决EXTJS文本框长度验证在ORACLE数据库下不正确的问题

    由于ORACLE数据库里面一个汉字和符号占2 个字节,数字和英文占1个字节,所以用EXTJS的文本框MaxLenght去限制输入的长度是不正确的,因为EXTJS只限制了输入的字数量,而不是字节数量. ...

  8. Aptana studio 3配色方案的修改方法

    http://www.weste.net/2013/1-29/88614.html Aptana studio 3的确是一个不错的IDE,但是默认的黑底白色代码样式看时间长了有点审美疲劳了,如何能够更 ...

  9. USB PIC Programmer (Brenner8)

    http://uzzors2k.4hv.org/index.php?page=usbpicprog My Tait Serial programmer works alright, but not e ...

  10. 使用Microsoft Unity进行日志记录

    需要记录日志的地方包括:进入方法的时候,传参的时候,统计执行时间,方法返回参数的时候,退出语句块的时候,出现异常的时候,等等.先来体验不使用Micirosoft Unity进行日志记录. class ...