Silverlight自定义控件系列 – TreeView (4) 缩进
接下来是缩进,没有缩进的Tree怎么看都不顺眼。
首先,定义节点深度Depth(注:回叫方法暂没有代码,以后要用到):
1: /// <summary>
2: /// Using a DependencyProperty as the backing store for Depth. This enables animation, styling, binding, etc...
3: /// </summary>
4: public static readonly DependencyProperty DepthProperty =
5: DependencyProperty.Register("Depth", typeof(int), typeof(FancyTreeViewItem),
6: new PropertyMetadata(0, new PropertyChangedCallback(FancyTreeViewItem.OnDepthPropertyChanged))
7: );
8:
1: /// <summary>
2: /// Gets or sets the node depth level in tree
3: /// </summary>
4: public int Depth
5: {
6: get { return (int)GetValue(DepthProperty); }
7: set { SetValue(DepthProperty, value); }
8: }
9:
1: /// <summary>
2: /// Call back when Depth property has been changed
3: /// </summary>
4: /// <param name="o">The target object</param>
5: /// <param name="e">>The property changed event arrguments</param>
6: private static void OnDepthPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
7: {
8:
9: }
10:
接下来就是写出计算节点在树中深度值的方法:
1: /// <summary>
2: /// For getting the item depth level
3: /// </summary>
4: /// <returns>The result depth level</returns>
5: private int GetDepthLevel()
6: {
7: int depthLevel = 0;
8: FrameworkElement element = this;
9:
10: while (element.Parent != null)
11: {
12: var parent = element.Parent as FancyTreeViewItem;
13:
14: if (parent != null)
15: {
16: depthLevel++;
17: ////depthLevel = parent.GetDepthLevel() + 1;
18: }
19:
20: element = element.Parent as FrameworkElement;
21: }
22:
23: return depthLevel;
24: }
25:
绑定样式的时候把缩进量放进去,在public override void OnApplyTemplate()中添加:
1: if (this.Indent != null)
2: {
3: this.Indent.Width = this.GetDepthLevel() * 20;
4: }
5:
最后把Boder的边框颜色去掉,运行看效果:
图4.1 带缩进的效果图
Silverlight自定义控件系列 – TreeView (4) 缩进的更多相关文章
- Silverlight自定义控件系列 – TreeView (1)
原文路径:http://blog.csdn.net/wlanye/article/details/7265457 很多人都对MS自带的控件不太满意(虽然MS走的是简约风格),都会试图去修改或创建让 ...
- Silverlight自定义控件系列 – TreeView (2) 基本布局和States
TreeView的树形结构都以缩进方式显示,现在来完成这部分. 首先,要定义出每个节点上都包含什么东西.先看看Win7资源管理器的TreeView: 图2.1 资源管理器 一个通用的TreeView至 ...
- Silverlight自定义控件系列 – TreeView (3) 添加展开和收起事件
由于Writer嫌我文章过长,只能把上篇拆开两半了.以下是接着上篇的. 准备工作做完了,现在就要完成点击事件. 定义Expander和单击事件: 1: /// <summary> 2: / ...
- 一步一步学Silverlight 2系列文章
概述 由TerryLee编写的<Silverlight 2完美征程>一书,已经上市,在该系列文章的基础上补充了大量的内容,敬请关注.官方网站:http://www.dotneteye.cn ...
- 一步一步学Silverlight 2系列(32):图形图像综合实例—“功夫之王”剧照播放
概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...
- 一步一步学Silverlight 2系列(31):图形图像综合实例—实现水中倒影效果
概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...
- 一步一步学Silverlight 2系列(30):使用Transform实现更炫的效果(下)
概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...
- 一步一步学Silverlight 2系列(29):使用Transform实现更炫的效果(上)
概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...
- 一步一步学Silverlight 2系列(28):图片处理
概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...
随机推荐
- AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) Chapter 3. Data Structures Fundamental Data Structures
10410 这题说的是给了一棵多叉树的 bfs遍历轨迹 和dfs 遍历 轨迹 在父节点向叶子节点扩展的时候优先遍历编号较小的节点.我还原出这课树特殊判定 根据bfs的顺序来建立这课树,用一个队列安排要 ...
- MATLAB 简明教程
MATAB 是我学习和接触的第一种工具类的编程语言,最早可以追溯到大一上数学分析这门课的时候.MATLAB既是一种软件也是一门编程语言,MATLAB功能强大在理科和工科中运用较多. MATLAB 是 ...
- linux常用命令:ifconfig 命令
许多windows非常熟悉ipconfig命令行工具,它被用来获取网络接口配置信息并对此进行修改.Linux系统拥有一个类似的工具,也就是ifconfig(interfaces config).通常需 ...
- 2018-2019-2 20165209 《网络对抗技术》Exp5:MSF基础应用
2018-2019-2 20165209 <网络对抗技术>Exp5:MSF基础应用 目录 一.基础问题回答和实验内容 二.攻击实例 主动攻击的实践 ms08_067 payload/gen ...
- tomcat启动失败问题排除及解决办法 Server Tomcat v7.0 Server at localhost failed to start.
tomcat启动失败问题排除及解决办法 Server Tomcat v7.0 Server at localhost failed to start. 导致上面问题的原因可能有很多种,每种的解决办法都 ...
- win10锁屏界面无法更新
win10的锁屏界面都是巨硬公司推送过来的,质量还不错,最近锁屏界面无法更新,解决方案如下: 以管理员身份运行cmd,分别运行如下两个命令 del /f /s /q /a "%userpro ...
- 原生JS操作AJAX
1,get方式的AJAX function sendAjaxReq() { //1,创建ajax引擎 XMLHttpRequest对象 var req = new XMLHttpRequest() | ...
- MemcacheQ安装
一.memcacheq介绍 特性: 1.简单易用 2.处理速度快 3.多条队列 4.并发性能好 5.与memcache的协议兼容 6.在zend framework中使用方便 memcacheq依赖于 ...
- bzoj 2118 墨墨的等式 - 图论最短路建模
墨墨突然对等式很感兴趣,他正在研究a1x1+a2y2+…+anxn=B存在非负整数解的条件,他要求你编写一个程序,给定N.{an}.以及B的取值范围,求出有多少B可以使等式存在非负整数解. Input ...
- Linux slab分配器【转】
本文转载自:https://www.ibm.com/developerworks/cn/linux/l-linux-slab-allocator/ 良好的操作系统性能部分依赖于操作系统有效管理资源的能 ...