silverlight   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Silverlight自定义控件系列 – TreeView (4) 缩进大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

  http://blog.sina.com.cn/s/blog_7019da0c0100lpwv.html 接下来是缩进,没有缩进的Tree怎么看都不顺眼。 首先,定义节点深度Depth(注:回叫方法暂没有代码,以后要用到): 1: /// <sumMary> 2: /// Using a DependencyProperty as the BACking store for Depth.
 

http://blog.sina.com.cn/s/blog_7019da0c0100lpwv.html

接下来是缩进,没有缩进的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: depthLeve@L_944_6@;
 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的边框颜色去掉,运行看效果

Silverlight自定义控件系列 – TreeView (4) 缩进

图4.1 带缩进的效果

@H_364_404@

大佬总结

以上是大佬教程为你收集整理的Silverlight自定义控件系列 – TreeView (4) 缩进全部内容,希望文章能够帮你解决Silverlight自定义控件系列 – TreeView (4) 缩进所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。