Visual Tree
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的更多相关文章
- 2000条你应知的WPF小姿势 基础篇<45-50 Visual Tree&Logic Tree 附带两个小工具>
在正文开始之前需要介绍一个人:Sean Sexton. 来自明尼苏达双城的软件工程师.最为出色的是他维护了两个博客:2,000Things You Should Know About C# 和 2,0 ...
- UWP开发入门(十二)——神器Live Visual Tree
很久以前,我们就有Snoop这样的工具实时修改.查看正在运行的WPF程序,那时候调个样式,修改个模板,相当滋润.随着历史的车轮陷进WP的泥潭中,无论WP7的Silverlight还是WP8.1的run ...
- How to remove live visual tree?
How to remove live visual tree? How to不显示实时可视化树 Remove the "Go to live visual tree" / &quo ...
- WPF中的Visual Tree和Logical Tree与路由事件
1.Visual Tree和Logical TreeLogical Tree:逻辑树,WPF中用户界面有一个对象树构建而成,这棵树叫做逻辑树,元素的声明分层结构形成了所谓的逻辑树!!Visual Tr ...
- WPF知识点全攻略06- WPF逻辑树(Logical Tree)和可视树(Visual Tree)
介绍概念之前,先来分析一段代码: xaml代码如下: <Window x:Class="WpfApp1.MainWindow" xmlns="http://sche ...
- WPF中Logical Tree和Visual Tree的区别
The Logical TreeThe logical tree describes the relations between elements of the user interface. The ...
- WPF 中的逻辑树(Logical Tree)与可视化元素树(Visual Tree)
一.前言 WPF 中有两种"树":逻辑树(Logical Tree)和可视化元素树(Visual Tree). Logical Tree 最显著的特点就是它完全由布局组件和控件 ...
- Visual Studio 2015 CTP6 发布
微软发布ASP.NET 5 支持在Windows.Mac和Linux上构建程序,Visual Studio 2015 CTP6(社区预览版)现已发布了.感兴趣的朋友们可以登录官网下载[http://w ...
- Visual Studio 2015速递(2)——提升效率和质量(VS2015核心竞争力)
系列文章 Visual Studio 2015速递(1)——C#6.0新特性怎么用 Visual Studio 2015速递(2)——提升效率和质量(VS2015核心竞争力) Visual Studi ...
随机推荐
- 【SQL】181. Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there ...
- Rsync服务部署使用
rsync服务搭建过程(daemon模式) 配置服务 在/etc/rsyncd.conf文件中写入相应的配置: uid = root gid = root use chroot = no max co ...
- tensorflow模块安装
有时候,我们的电脑上或许会同时安装多个python的环境,譬如,我的电脑上同时装了anaconda2和3. 在安装的时候,譬如,我想在python3中装tensorflow,则需要在 C:\Progr ...
- C# CuttingEdge.Conditions 验证帮助类库 文档翻译
项目主页: https://archive.codeplex.com/?p=conditions 作者博客关于项目的文档(翻译原文): https://www.cuttingedge.it/blogs ...
- ShellExecuteA函数
原型: ShellExecuteA(, , , );//最大化打开记事本 第一个参数//系统启动第二个参数//open打开第三个参数//指令第四个参数//默认0第五个参数//默认0第六个参数//0隐藏 ...
- 安装第三方jar包的两种方式
由于部分第三放jar包没有放到maven中央仓库,而项目中又依赖了这些jar包,那么如何安装?我实践了两种,特做记录. 一.安装到 nexus 私有库: 在 3rd party 仓库下有个 Artif ...
- gradle/maven/eclipse工程相互转化
原文: gradle/maven/eclipse工程相互转化 gradle/maven/eclipse工程相互转化:前提安装好相应的工具和插件.1.Maven->eclipse mvn ecl ...
- Codeforces Round #248 (Div. 1) A. Ryouko's Memory Note 水题
A. Ryouko's Memory Note 题目连接: http://www.codeforces.com/contest/434/problem/A Description Ryouko is ...
- 恢复二进制文件中的block符号表
前篇博客中,使用 杨君的小黑屋 提供的工具恢复二进制文件的符号表,只恢复了函数的符号表,本篇讲述如何恢复block符号表,杨君的博客中使用IDA分析二进制文件,本篇则使用MacOS系统上体验也不错的H ...
- Caffe2(3)----下载现成的模型并使用
Caffe2训练好的模型可在Model Zoo下载,下载的命令很简单,接下来以下载和使用squeezenet为例,进行简单说明. 1.浏览可下载的模型 已有模型都放在github上,地址:https: ...