Exemple #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="TreeView"></param>
 /// <param name="TreeViewItem"></param>
 public static void SelectItemsRandomly(this TreeView TreeView, TreeViewItem TreeViewItem)
 {
     TreeViewItemExtensions.SetIsSelected(TreeViewItem, !TreeViewItemExtensions.GetIsSelected(TreeViewItem));
     if (TreeViewExtensions.GetStartItem(TreeView) == null || Keyboard.Modifiers == ModifierKeys.Control)
     {
         if (TreeViewItemExtensions.GetIsSelected(TreeViewItem))
         {
             TreeViewExtensions.SetStartItem(TreeView, TreeViewItem);
         }
     }
     else
     {
         if (TreeViewExtensions.GetSelectedItems(TreeView).Count == 0)
         {
             TreeViewExtensions.SetStartItem(TreeView, null);
         }
     }
 }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="TreeView"></param>
        /// <param name="TreeViewItem"></param>
        /// <param name="ShiftControl"></param>
        public static void SelectItemsContinuously(this TreeView TreeView, TreeViewItem TreeViewItem, bool ShiftControl = false)
        {
            var StartItem = TreeViewExtensions.GetStartItem(TreeView);

            if (StartItem != null)
            {
                if (StartItem == TreeViewItem)
                {
                    SelectItem(TreeView, TreeViewItem);
                    return;
                }
                var AllItems = new List <TreeViewItem>();
                GetAllItems(TreeView, AllItems);

                bool IsBetween = false;
                foreach (var Item in AllItems)
                {
                    if (Item == TreeViewItem || Item == StartItem)
                    {
                        //Toggle to true if first element is found and back to false if last element is found
                        IsBetween = !IsBetween;
                        //Set boundary element
                        TreeViewItemExtensions.SetIsSelected(Item, true);
                        continue;
                    }
                    if (IsBetween)
                    {
                        TreeViewItemExtensions.SetIsSelected(Item, true);
                        continue;
                    }
                    if (!ShiftControl)
                    {
                        TreeViewItemExtensions.SetIsSelected(Item, false);
                    }
                }
            }
        }