private void ExpandParent(AyTreeViewItemModel model)
 {
     if (model.ParentCategory != null)
     {
         model.ParentCategory.IsExpanded = true;
         ExpandParent(model.ParentCategory);
     }
 }
 public AyTreeViewItemModel(string text, string icon, AyTreeViewItemModel parent)
 {
     this.text   = text;
     this.parent = parent;
     this.Icon   = icon;
     UpdateDepth(true);
     Uid = Guid.NewGuid();
 }
 private void ExpandAllChildren1(AyTreeViewItemModel model)
 {
     foreach (var item in model.Children)
     {
         item.IsExpanded = true;
         if (item.Children.Count > 0)
         {
             ExpandAllChildren1(item);
         }
     }
 }
 private void CollapseAllChildren1(AyTreeViewItemModel model)
 {
     foreach (var item in model.Children)
     {
         item.IsExpanded = false;
         if (item.Children.Count > 0)
         {
             CollapseAllChildren1(item);
         }
     }
 }
예제 #5
0
        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);
        }
        /// <summary>
        /// 只移除下一级的子,不会递归移除
        /// </summary>
        /// <param name="id"></param>
        public void RemoveChild(string id)
        {
            AyTreeViewItemModel d = null;

            foreach (var item in Children)
            {
                if (item.id == id)
                {
                    d = item;
                    break;
                }
            }
            Children.Remove(d);
            d = null;
        }
예제 #7
0
        /// <summary>
        /// 根据xml生成菜单
        /// 用法例如     return AyTreeViewMenuFromXml.Gets(System.IO.Directory.GetCurrentDirectory()+"/Config/sysmenu.xml");
        /// 注意,xml节点必须 按照先父节点,然后子节点的顺序增加,结构为 Nav,NavItem不可改变
        /// 作者:ay       2015-9-22 11:59:25
        /// </summary>
        /// <param name="xmlPath"></param>
        /// <returns></returns>
        public static ObservableCollection <AyTreeViewItemModel> CreateMenuFromXml(string xmlPath)
        {
            List <AyTreeViewItemModel> items = new List <AyTreeViewItemModel>();

            if (System.IO.File.Exists(xmlPath))
            {
                XDocument doc = XDocument.Load(xmlPath);
                IEnumerable <XElement> elements = from xml in doc.Element("Nav").Elements()
                                                  select xml;
                if (elements.Count() > 0)
                {
                    foreach (var item in elements)
                    {
                        string pid = item.Attribute("pid").Value;
                        string id  = item.Attribute("id").Value;
                        if (pid != "0")
                        {
                            AyTreeViewItemModel a = (from o in items where o.Id.Equals(pid) select o).FirstOrDefault();
                            if (a != null)
                            {
                                AyTreeViewItemModel node = new AyTreeViewItemModel(item.Value, item.Attribute("icon").Value, a, item.Attribute("isExpanded").Value == "false" ? false : true, item.Attribute("uri").Value);
                                node.Pid        = pid;
                                node.Id         = id;
                                node.IsSelected = item.Attribute("isSelected").Value == "false" ? false : true;
                            }
                        }
                        else
                        {
                            AyTreeViewItemModel node = new AyTreeViewItemModel(item.Value, item.Attribute("icon").Value, null, item.Attribute("isExpanded").Value == "false" ? false : true, item.Attribute("uri").Value);
                            node.Pid        = pid;
                            node.Id         = id;
                            node.IsSelected = item.Attribute("isSelected").Value == "false" ? false : true;
                            items.Add(node);
                        }
                    }
                }
            }
            else
            {
                throw new Exception(xmlPath + "文件不存在!");
            }
            return(new ObservableCollection <AyTreeViewItemModel>(items));
        }
예제 #8
0
        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)
                {
                    itemhost.Visibility = Visibility.Visible;
                    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(string text, string icon, AyTreeViewItemModel parent, bool isExpanded, object[] extValues)
     : this(text, icon, parent, isExpanded)
 {
     this.ExtValues = extValues;
 }
 public AyTreeViewItemModel(string text, string icon, AyTreeViewItemModel parent, bool isExpanded, object[] extValues, int nodetype) : this(text, icon, parent, isExpanded, extValues)
 {
     this.NodeType = nodetype;
 }
 public AyTreeViewItemModel(string text, string icon, AyTreeViewItemModel parent, bool isExpanded) : this(text, icon, parent)
 {
     this.IsExpanded = isExpanded;
 }
 public AyTreeViewItemModel(string text, string icon, AyTreeViewItemModel parent, int nodetype) : this(text, icon, parent)
 {
     this.NodeType = nodetype;
 }
 public AyTreeViewItemModel(string text, AyTreeViewItemModel parent)
     : this(text, null, parent)
 {
 }
예제 #14
0
        /// <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 (IsNeedMoveAndOpacity)
                    {
                        if (temp.RelativeItem != null)
                        {
                            temp.RelativeItem.Opacity = 0;
                        }
                    }
                }

                targetHeight += (TreeViewItemHeight + OtherBorderTreeViewHeight) * 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)));
                    HeightKey.KeyFrames.Add(HeightKey0);
                    if (IsNeedMoveAndOpacity)
                    {
                        EasingDoubleKeyFrame HeightKey1 = new EasingDoubleKeyFrame(targetHeight, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(ExpandedTime)), easyOut);
                        HeightKey.KeyFrames.Add(HeightKey1);
                    }
                    else
                    {
                        EasingDoubleKeyFrame HeightKey1 = new EasingDoubleKeyFrame(targetHeight, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(ExpandedTime)));
                        HeightKey.KeyFrames.Add(HeightKey1);
                    }
                    itemhost.BeginAnimation(ItemsPresenter.HeightProperty, null);
                    itemhost.BeginAnimation(ItemsPresenter.HeightProperty, HeightKey);
                }
                if (IsNeedMoveAndOpacity)
                {
                    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 += 30;
                            if (endIndex == index)
                            {
                                temp.RelativeItem.BringIntoView();
                            }
                        }
                    }
                    executeTime = 0;
                }
            }
            e.Handled = true;
        }
예제 #15
0
 public AuthTreeViewItemModel(string text, string icon, AyTreeViewItemModel parent, bool isExpanded, object extValue) : base(text, icon, parent, isExpanded, extValue)
 {
 }