Ejemplo n.º 1
0
        private void HandleInput(RoutedEventArgs e)
        {
            if (beginSelect)
            {
                List <object> itemsToSelect   = new List <object>();
                List <object> itemsToUnSelect = new List <object>();

                // if the mouse position or the start point is outside the window, we trim it inside
                Point currentPoint      = TrimPointToVisibleArea(GetMousePositionRelativeToContent());
                Point trimmedStartPoint = TrimPointToVisibleArea(selectPosition.Value);

                Rect selectionRect = new Rect(currentPoint, trimmedStartPoint);
                border.UpdatePosition(selectionRect);

                if (!SelectionMultiple.IsControlKeyDown)
                {
                    foreach (var item in TreeView.SelectedItems)
                    {
                        var  treeViewItem = TreeView.GetTreeViewItemFor(item);
                        Rect itemRect     = GetPositionOf(treeViewItem);

                        if (!selectionRect.IntersectsWith(itemRect))
                        {
                            itemsToUnSelect.Add(item);
                        }
                    }
                }

                foreach (var item in items)
                {
                    if (!item.IsVisible || item.IsEditing)
                    {
                        continue;
                    }

                    Rect itemRect = GetPositionOf(item);

                    if (selectionRect.IntersectsWith(itemRect))
                    {
                        if (!TreeView.SelectedItems.Contains(item.DataContext))
                        {
                            itemsToSelect.Add(item.DataContext);
                        }
                    }
                    else
                    {
                        if (!SelectionMultiple.IsControlKeyDown && TreeView.SelectedItems.Contains(item.DataContext))
                        {
                            itemsToUnSelect.Add(item.DataContext);
                        }
                    }
                }
                ((SelectionMultiple)TreeView.Selection).SelectByRectangle(itemsToSelect, itemsToUnSelect);
            }
        }
Ejemplo n.º 2
0
        private void HandleInput(RoutedEventArgs e)
        {
            if (mouseDown)
            {
                if (Mouse.LeftButton == MouseButtonState.Released)
                {
                    mouseDown = false;
                    if (border != null)
                    {
                        border.Visibility = Visibility.Collapsed;
                        border.Dispose();
                    }

                    return;
                }

                if (startPoint == GetMousePositionRelativeToContent())
                {
                    return;
                }

                List <object> itemsToSelect   = new List <object>();
                List <object> itemsToUnSelect = new List <object>();

                // if the mouse position or the start point is outside the window, we trim it inside
                Point currentPoint      = TrimPointToVisibleArea(GetMousePositionRelativeToContent());
                Point trimmedStartPoint = TrimPointToVisibleArea(startPoint);

                if (isFirstMove)
                {
                    isFirstMove = false;
                    border      = new BorderSelectionAdorner(TreeView);
                }

                Rect selectionRect = new Rect(currentPoint, trimmedStartPoint);
                border.UpdatePosition(selectionRect);


                if (isFirstMove)
                {
                    if (!SelectionMultiple.IsControlKeyDown)
                    {
                        foreach (var item in TreeView.SelectedItems)
                        {
                            var  treeViewItem = TreeView.GetTreeViewItemFor(item);
                            Rect itemRect     = GetPositionOf(treeViewItem);

                            if (!selectionRect.IntersectsWith(itemRect))
                            {
                                itemsToUnSelect.Add(item);
                            }
                        }
                    }
                }

                foreach (var item in items)
                {
                    if (!item.IsVisible || item.IsEditing)
                    {
                        continue;
                    }

                    Rect itemRect = GetPositionOf(item);

                    if (selectionRect.IntersectsWith(itemRect))
                    {
                        if (isFirstMove)
                        {
                            itemsToSelect.Add(item.DataContext);
                        }
                        else
                        {
                            if (!TreeView.SelectedItems.Contains(item.DataContext))
                            {
                                itemsToSelect.Add(item.DataContext);
                            }
                        }
                    }
                    else
                    {
                        if (!SelectionMultiple.IsControlKeyDown && TreeView.SelectedItems.Contains(item.DataContext))
                        {
                            itemsToUnSelect.Add(item.DataContext);
                        }
                    }
                }

                ((SelectionMultiple)TreeView.Selection).SelectByRectangle(itemsToSelect, itemsToUnSelect);
                e.Handled = true;
            }
        }