public bool SelectPreviousFromKey()
        {
            List <MultiSelectTreeViewItem> items = MultiSelectTreeView.RecursiveTreeViewItemEnumerable(treeView, false, false).ToList();
            MultiSelectTreeViewItem        item  = treeView.GetPreviousItem(GetFocusedItem(), items);

            return(SelectFromKey(item));
        }
        public bool SelectLastFromKey()
        {
            List <MultiSelectTreeViewItem> items = MultiSelectTreeView.RecursiveTreeViewItemEnumerable(treeView, false, false).ToList();
            MultiSelectTreeViewItem        item  = treeView.GetLastItem(items);

            return(SelectFromKey(item));
        }
Пример #3
0
        public BorderSelectionLogic(MultiSelectTreeView treeView, Border selectionBorder, ScrollViewer scrollViewer, ItemsPresenter content, IEnumerable <MultiSelectTreeViewItem> items)
        {
            if (treeView == null)
            {
                throw new ArgumentNullException("treeView");
            }
            if (selectionBorder == null)
            {
                throw new ArgumentNullException("selectionBorder");
            }
            if (scrollViewer == null)
            {
                throw new ArgumentNullException("scrollViewer");
            }
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }

            this.treeView     = treeView;
            this.border       = selectionBorder;
            this.scrollViewer = scrollViewer;
            this.content      = content;
            this.items        = items;

            treeView.MouseDown += OnMouseDown;
            treeView.MouseMove += OnMouseMove;
            treeView.MouseUp   += OnMouseUp;
            treeView.KeyDown   += OnKeyDown;
            treeView.KeyUp     += OnKeyUp;
        }
        public BorderSelectionLogic(MultiSelectTreeView treeView, Border selectionBorder, ScrollViewer scrollViewer, ItemsPresenter content, IEnumerable<MultiSelectTreeViewItem> items)
        {
            if (treeView == null)
            {
                throw new ArgumentNullException("treeView");
            }
            if (selectionBorder == null)
            {
                throw new ArgumentNullException("selectionBorder");
            }
            if (scrollViewer == null)
            {
                throw new ArgumentNullException("scrollViewer");
            }
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }

            this.treeView = treeView;
            this.border = selectionBorder;
            this.scrollViewer = scrollViewer;
            this.content = content;
            this.items = items;

            treeView.MouseDown += OnMouseDown;
            treeView.MouseMove += OnMouseMove;
            treeView.MouseUp += OnMouseUp;
            treeView.KeyDown += OnKeyDown;
            treeView.KeyUp += OnKeyUp;
        }
Пример #5
0
        private static void OnSelectionModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MultiSelectTreeView treeView = (MultiSelectTreeView)d;

            if (treeView.Selection != null)
            {
                treeView.Selection.PreviewSelectionChanged -= treeView.PreviewSelectionChangedHandler;
            }

            switch ((TreeViewSelectionMode)e.NewValue)
            {
            case TreeViewSelectionMode.MultiSelectEnabled:
                treeView.Selection = new SelectionMultiple(treeView);
                break;

            case TreeViewSelectionMode.SingleSelectOnly:
                treeView.Selection = new SelectionSingle(treeView);
                break;
            }

            if (treeView.Selection != null)
            {
                treeView.Selection.PreviewSelectionChanged += treeView.PreviewSelectionChangedHandler;
            }
        }
 public void ApplyTemplate()
 {
     borderSelectionLogic = new BorderSelectionLogic(
         treeView,
         treeView.Template.FindName("selectionBorder", treeView) as Border,
         treeView.Template.FindName("scrollViewer", treeView) as ScrollViewer,
         treeView.Template.FindName("content", treeView) as ItemsPresenter,
         MultiSelectTreeView.RecursiveTreeViewItemEnumerable(treeView, false, false));
 }
 private MultiSelectTreeViewItem GetFocusedItem()
 {
     foreach (var item in MultiSelectTreeView.RecursiveTreeViewItemEnumerable(treeView, false, false))
     {
         if (item.IsFocused)
         {
             return(item);
         }
     }
     return(null);
 }
 public void Dispose()
 {
     if (treeView != null)
     {
         treeView.MouseDown -= OnMouseDown;
         treeView.MouseMove -= OnMouseMove;
         treeView.MouseUp -= OnMouseUp;
         treeView.KeyDown -= OnKeyDown;
         treeView.KeyUp -= OnKeyUp;
         treeView = null;
     }
     GC.SuppressFinalize(this);
 }
Пример #9
0
 public void Dispose()
 {
     if (treeView != null)
     {
         treeView.MouseDown -= OnMouseDown;
         treeView.MouseMove -= OnMouseMove;
         treeView.MouseUp   -= OnMouseUp;
         treeView.KeyDown   -= OnKeyDown;
         treeView.KeyUp     -= OnKeyUp;
         treeView            = null;
     }
     GC.SuppressFinalize(this);
 }
        private bool SelectPageUpDown(bool down)
        {
            List <MultiSelectTreeViewItem> items = MultiSelectTreeView.RecursiveTreeViewItemEnumerable(treeView, false, false).ToList();
            MultiSelectTreeViewItem        item  = GetFocusedItem();

            if (item == null)
            {
                return(down ? SelectLastFromKey() : SelectFirstFromKey());
            }

            double           targetY     = item.TransformToAncestor(treeView).Transform(new Point()).Y;
            FrameworkElement itemContent = (FrameworkElement)item.Template.FindName("PART_Header", item);

            if (itemContent == null)
            {
                return(down ? SelectLastFromKey() : SelectFirstFromKey());
            }

            double offset = treeView.ActualHeight - 2 * ((FrameworkElement)itemContent.Parent).ActualHeight;

            if (!down)
            {
                offset = -offset;
            }
            targetY += offset;
            while (true)
            {
                var newItem = down ? treeView.GetNextItem(item, items) : treeView.GetPreviousItem(item, items);
                if (newItem == null)
                {
                    break;
                }
                item = newItem;
                double itemY = item.TransformToAncestor(treeView).Transform(new Point()).Y;
                if (down && itemY > targetY ||
                    !down && itemY < targetY)
                {
                    break;
                }
            }
            return(SelectFromKey(item));
        }
        public bool SelectAllFromKey()
        {
            var items = MultiSelectTreeView.RecursiveTreeViewItemEnumerable(treeView, false, false).ToList();

            // Add new selected items
            foreach (var item in items.Where(i => !treeView.SelectedItems.Contains(i.DataContext)))
            {
                var e = new PreviewSelectionChangedEventArgs(true, item.DataContext);
                OnPreviewSelectionChanged(e);
                if (e.CancelAll)
                {
                    return(false);
                }
                if (!e.CancelThis)
                {
                    treeView.SelectedItems.Add(item.DataContext);
                }
            }
            return(true);
        }
Пример #12
0
		private static void OnSelectedItemsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			MultiSelectTreeView treeView = (MultiSelectTreeView) d;
			if (e.OldValue != null)
			{
				INotifyCollectionChanged collection = e.OldValue as INotifyCollectionChanged;
				if (collection != null)
				{
					collection.CollectionChanged -= treeView.OnSelectedItemsChanged;
				}
			}

			if (e.NewValue != null)
			{
				INotifyCollectionChanged collection = e.NewValue as INotifyCollectionChanged;
				if (collection != null)
				{
					collection.CollectionChanged += treeView.OnSelectedItemsChanged;
				}
			}
		}
 protected override void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
 {
     // Remove all items from the SelectedItems list that are no longer in the Items
     if (oldValue != null)
     {
         MultiSelectTreeView parentTV = ParentTreeView;
         if (parentTV == null)
         {
             parentTV = lastParentTreeView;
         }
         if (parentTV != null)
         {
             foreach (var item in oldValue)
             {
                 parentTV.SelectedItems.Remove(item);
                 if (parentTV.Selection is SelectionMultiple multiselection)
                 {
                     multiselection.InvalidateLastShiftRoot(item);
                 }
             }
         }
     }
 }
Пример #14
0
 public static void Focus(MultiSelectTreeView element)
 {
     //System.Diagnostics.Debug.WriteLine("Focus Tree with helper");
     FocusCore(element);
     element.BringIntoView();
 }
 public SelectionMultiple(MultiSelectTreeView treeView)
 {
     this.treeView = treeView;
 }
Пример #16
0
 public SelectionMultiple(MultiSelectTreeView treeView)
 {
     this.treeView = treeView;
 }
		public static void Focus(MultiSelectTreeView element)
		{
			//System.Diagnostics.Debug.WriteLine("Focus Tree with helper");
			FocusCore(element);
			element.BringIntoView();
		}
		public MultiSelectTreeViewAutomationPeer(MultiSelectTreeView owner)
			: base(owner)
		{
		}