public int GetTreeViewItemCount(AyTreeViewItemModel temp) { int a = 1; if (temp.IsExpanded && temp.Children != null) { foreach (var item in temp.Children) { a += GetTreeViewItemCount(item); } } return(a); }
public AyTreeViewItemModel(string text, AyTreeViewItemModel parent) : this(text, null, parent) { if (parent != null) { this.Depth = parent.Depth + 1; if (parent.children.Count > 0) { parent.IsCatagory = true; } parent.children.Add(this); } Uid = Guid.NewGuid(); }
public AyTreeViewItemModel(string text, string icon, AyTreeViewItemModel parent) { this.text = text; this.parent = parent; this.Icon = icon; if (parent != null) { parent.children.Add(this); if (parent.children.Count > 0) { parent.IsCatagory = true; } this.Depth = parent.Depth + 1; } Uid = Guid.NewGuid(); }
public AyTreeViewItemModel(string text, string icon, AyTreeViewItemModel parent, bool isExpanded, object[] extValues) { this.text = text; this.parent = parent; this.Icon = icon; this.IsExpanded = isExpanded; if (parent != null) { parent.children.Add(this); if (parent.children.Count > 0) { parent.IsCatagory = true; } this.Depth = parent.Depth + 1; } this.ExtValues = extValues; Uid = Guid.NewGuid(); }
public AyTreeViewItemModel(string text, string icon, AyTreeViewItemModel parent, bool isExpanded, bool isSpecParentN) { this.text = text; this.parent = parent; this.Icon = icon; this.IsExpanded = isExpanded; this.IsSpecParentNode = isSpecParentN; if (parent != null) { parent.children.Add(this); if (parent.children.Count > 0) { parent.IsCatagory = true; } this.Depth = parent.Depth + 1; } Uid = Guid.NewGuid(); }
private void AyTreeViewItemCollapsed(object sender, RoutedEventArgs e) { TreeViewItem tvi = e.OriginalSource as TreeViewItem; //tvi.IsExpanded = false; if (tvi != null && tvi.Items.Count > 0) { itemhost = WpfTreeHelper.GetChildObject <ItemsPresenter>(tvi, "ItemsHost"); // double targetHeight = 0; ////添加动画 foreach (var item in tvi.Items) { AyTreeViewItemModel temp = item as AyTreeViewItemModel; if (temp.RelativeItem != null) { temp.ParentCategory.IsExpanded = false; break; } } if (itemhost != null) { DoubleAnimationUsingKeyFrames HeightKey = new DoubleAnimationUsingKeyFrames(); HeightKey.Duration = new Duration(TimeSpan.FromMilliseconds(ExpandedTime)); HeightKey.FillBehavior = FillBehavior.Stop; EasingDoubleKeyFrame HeightKey0 = new EasingDoubleKeyFrame(itemhost.ActualHeight, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0))); EasingDoubleKeyFrame HeightKey1 = new EasingDoubleKeyFrame(0); HeightKey1.EasingFunction = easyOut; HeightKey.KeyFrames.Add(HeightKey0); HeightKey.KeyFrames.Add(HeightKey1); HeightKey.Completed += HeightKey_Completed; itemhost.BeginAnimation(ItemsPresenter.HeightProperty, HeightKey); } } e.Handled = true; }
public AyTreeViewItemModel TryFindNodeByName(AyTreeViewItemModel parent, string text) { ObservableCollection <AyTreeViewItemModel> cats; cats = parent == null ? nodes : parent.Children; foreach (AyTreeViewItemModel category in cats) { if (category.Text == text) { return(category); } else { AyTreeViewItemModel cat = TryFindNodeByName(category, text); if (cat != null) { return(cat); } } } return(null); }
/// <summary> /// 每个时常都是一样的,暂定200 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AyTreeViewItemExpanded(object sender, RoutedEventArgs e) { TreeViewItem tvi = e.OriginalSource as TreeViewItem; if (tvi != null && tvi.Items.Count > 0) { int executeTime = 0;//执行time误差 int durationTime = 300; double targetHeight = 0; int expandNode = 0; //添加动画 foreach (var item in tvi.Items) { AyTreeViewItemModel temp = item as AyTreeViewItemModel; temp.ParentCategory.IsExpanded = true; if (temp.RelativeItem == null) { temp.RelativeItem = TreeViewHelper.GetTreeViewItem2(tvi, temp); } expandNode += GetTreeViewItemCount(temp); if (temp.RelativeItem != null) { temp.RelativeItem.Opacity = 0; } } targetHeight += (TreeViewItemHeight + 2) * expandNode;//计算当前展开的有多少个item //set itemhost的高度 var itemhost = WpfTreeHelper.GetChildObject <ItemsPresenter>(tvi, "ItemsHost"); if (itemhost != null) { itemhost.Visibility = Visibility.Visible; DoubleAnimationUsingKeyFrames HeightKey = new DoubleAnimationUsingKeyFrames(); HeightKey.FillBehavior = FillBehavior.Stop; EasingDoubleKeyFrame HeightKey0 = new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0))); EasingDoubleKeyFrame HeightKey1 = new EasingDoubleKeyFrame(targetHeight, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(ExpandedTime)), easyOut); HeightKey.KeyFrames.Add(HeightKey0); HeightKey.KeyFrames.Add(HeightKey1); itemhost.BeginAnimation(ItemsPresenter.HeightProperty, null); itemhost.BeginAnimation(ItemsPresenter.HeightProperty, HeightKey); } int index = 0; int endIndex = tvi.Items.Count; //添加动画 foreach (var item in tvi.Items) { AyTreeViewItemModel temp = item as AyTreeViewItemModel; if (temp.RelativeItem != null) { index++; DoubleAnimationUsingKeyFrames OpacityKey = new DoubleAnimationUsingKeyFrames(); EasingDoubleKeyFrame opacityKey10 = new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0))); EasingDoubleKeyFrame opacityKey0 = new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(executeTime))); EasingDoubleKeyFrame opacityKey1 = new EasingDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(executeTime + durationTime))); opacityKey1.EasingFunction = easyIn; OpacityKey.KeyFrames.Add(opacityKey0); OpacityKey.KeyFrames.Add(opacityKey1); ThicknessAnimationUsingKeyFrames MarginKey = new ThicknessAnimationUsingKeyFrames(); var tempThickness = GetTargetThickness(temp.Depth); MarginKey.KeyFrames.Add(new EasingThicknessKeyFrame(new Thickness(0, 0, 0, 0), KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)))); MarginKey.KeyFrames.Add(new EasingThicknessKeyFrame(new Thickness(0, 0, 0, 0), KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(executeTime)))); MarginKey.KeyFrames.Add(new EasingThicknessKeyFrame(tempThickness, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(executeTime + durationTime)))); opacityKey1.EasingFunction = easyIn; temp.RelativeItem.BeginAnimation(TreeViewItem.OpacityProperty, null); temp.RelativeItem.BeginAnimation(TreeViewItem.OpacityProperty, OpacityKey); temp.RelativeItem.BeginAnimation(TreeViewItem.PaddingProperty, null); temp.RelativeItem.BeginAnimation(TreeViewItem.PaddingProperty, MarginKey); OpacityKey = null; MarginKey = null; executeTime += 44; if (endIndex == index) { temp.RelativeItem.BringIntoView(); } } } executeTime = 0; } e.Handled = true; }