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. .NET Core改造工程直播

    [背景] 新项目需要跨平台,原来积累的.NET类库需要改造为.NET Core. [直播] 新增加的项目不支持排除文件 不支持定义条件编译常量,虽然在项目中能使用#if语法,但无地方定义DefineC ...

  2. python opencv3 摄像头人脸检测

    git:https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 def detect(): # 创建人脸检测的对象 ...

  3. 机器学习之路: python 线性回归LinearRegression, 随机参数回归SGDRegressor 预测波士顿房价

    python3学习使用api 线性回归,和 随机参数回归 git: https://github.com/linyi0604/MachineLearning from sklearn.datasets ...

  4. 递归与分治策略之棋盘覆盖Java实现

    递归与分治策略之棋盘覆盖 一.问题描述 二.过程详解 1.棋盘如下图,其中有一特殊方格:16*16 . 2.第一个分割结果:8*8 3.第二次分割结果:4*4 4.第三次分割结果:2*2 5.第四次分 ...

  5. BZOJ.2286.[SDOI2011]消耗战(虚树 树形DP)

    题目链接 BZOJ 洛谷P2495 树形DP,对于每棵子树要么逐个删除其中要删除的边,要么直接断连向父节点的边. 如果当前点需要删除,那么直接断不需要再管子树. 复杂度O(m*n). 对于两个要删除的 ...

  6. [LearnOpenGL]照相机的变换、坐标系、摄像机

    前言 跟着LearnOpenGL上学着做项目,的确对于知识掌握得更清晰一些了. 第一个项目 第一个项目,是关于简单的熟悉矩阵变换的,创建了10个立方体,代码如下. // 视图矩阵,看作是一个照相机 g ...

  7. 洛谷P3119 USACO15JAN 草鉴定

    题目描述 In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-w ...

  8. BZOJ 1022 [SHOI2008]小约翰的游戏John AntiNim游戏

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1475  Solved: 932[Submit][ ...

  9. javaresource 红色X

    出现这个问题的原因很多,解决办法也很多,我这里只记录我所遇到的. 这个问题一直存在,但是不影响项目运行. 后来在网上找了下资料,有一篇文章是让修改maven的settings.xml.将jdk1.6修 ...

  10. 字符串转码【String.getBytes()和new String()】

    在Java中,String.getBytes(String decode)方法会根据指定的decode编码返回某字符串在该编码下的byte数组表示,如 byte[] b_gbk = "中&q ...