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, ...
随机推荐
- zw版【转发·台湾nvp系列Delphi例程】HALCON SigmaImage1
zw版[转发·台湾nvp系列Delphi例程]HALCON SigmaImage1 procedure TForm1.Button1Click(Sender: TObject);var img, im ...
- Spring 问题总结
Spring问答Top 25:http://www.importnew.com/15851.html [Java面试五]Spring总结以及在面试中的一些问题.:http://www.cnblogs. ...
- git仓库按时间、成员等维度分析统计
git 按时间打印所有成员代码提交: git log --since ==2018-01-01 --until=2018-12-31 --format='%aN' | sort -u | while ...
- AtCoder Beginner Contest 086 D - Checker
Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement AtCoDeer is thinking o ...
- 热心网友设计出更美的Windows 10开始菜单
开始菜单应该算是Windows操作系统的标志之一,Win8时微软曾做了大刀阔斧的改革,没想到招致一片负面评价,最终紧急推出了Win8.1系统. Win10推出后,微软等于整合了磁贴和传统风格,但也做不 ...
- sql study
-- ============================================= -- Author: lifu -- Create date: 2017-06-14 -- Descr ...
- Quartz框架调用Demo
Quartz框架调用Demo 任务调度在JAVA应用程序中运用的十分普遍,掌握QUARTZ是必备的技能; 官网:http://www.quartz-scheduler.org/ 下载最新1.80资源包 ...
- Python3.x(windows系统)安装requests库
Python3.x(windows系统)安装requests库 cmd命令: pip install requests 执行结果:
- 【运行错误】Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.
代码如下: <html> <head> <script> /*window.frames[]可以通过下标或名称访问单独的frame*/ window.onload= ...
- Python3基础 str + 字符串变量拼接
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...