Ejemplo n.º 1
0
        private void RectangleSelection_PointerReleased(object sender, PointerRoutedEventArgs e)
        {
            Canvas.SetLeft(selectionRectangle, 0);
            Canvas.SetTop(selectionRectangle, 0);
            selectionRectangle.Width  = 0;
            selectionRectangle.Height = 0;
            uiElement.PointerMoved   -= RectangleSelection_PointerMoved;
            uiElement.ReleasePointerCapture(e.Pointer);
            if (selectionChanged != null)
            {
                // Restore and trigger SelectionChanged event
                uiElement.SelectionChanged -= selectionChanged;
                uiElement.SelectionChanged += selectionChanged;
                if (prevSelectedItems == null || !uiElement.SelectedItems.SequenceEqual(prevSelectedItems))
                {
                    // Trigger SelectionChanged event if the selection has changed
                    selectionChanged(sender, null);
                }
            }
            if (selectionState == SelectionState.Active)
            {
                OnSelectionEnded();
            }

            selectionStrategy = null;
            selectionState    = SelectionState.Inactive;
        }
Ejemplo n.º 2
0
        private void RectangleSelection_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            itemsPosition.Clear();
            originDragPoint   = new Point(e.GetCurrentPoint(uiElement).Position.X, e.GetCurrentPoint(uiElement).Position.Y); // Initial drag point relative to the topleft corner
            prevSelectedItems = uiElement.SelectedItems.Cast <object>().ToList();                                            // Save current selected items
            var verticalOffset = scrollViewer?.VerticalOffset ?? 0;

            originDragPoint.Y += verticalOffset; // Initial drag point relative to the top of the list (considering scrolled offset)
            if (!e.GetCurrentPoint(uiElement).Properties.IsLeftButtonPressed || e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch)
            {
                // Trigger only on left click, do not trigger with touch
                return;
            }

            selectionStrategy = e.KeyModifiers.HasFlag(VirtualKeyModifiers.Control) ?
                                new InvertPreviousItemSelectionStrategy(uiElement.SelectedItems, prevSelectedItems) :
                                e.KeyModifiers.HasFlag(VirtualKeyModifiers.Shift) ?
                                (ItemSelectionStrategy) new ExtendPreviousItemSelectionStrategy(uiElement.SelectedItems, prevSelectedItems) :
                                new IgnorePreviousItemSelectionStrategy(uiElement.SelectedItems);

            selectionStrategy.HandleNoItemSelected();

            uiElement.PointerMoved -= RectangleSelection_PointerMoved;
            uiElement.PointerMoved += RectangleSelection_PointerMoved;
            if (selectionChanged != null)
            {
                // Unsunscribe from SelectionChanged event for performance
                uiElement.SelectionChanged -= selectionChanged;
            }
            uiElement.CapturePointer(e.Pointer);
            selectionState = SelectionState.Starting;
        }
        private void RectangleSelection_PointerReleased(object sender, PointerRoutedEventArgs e)
        {
            Canvas.SetLeft(selectionRectangle, 0);
            Canvas.SetTop(selectionRectangle, 0);
            selectionRectangle.Width  = 0;
            selectionRectangle.Height = 0;
            uiElement.PointerMoved   -= RectangleSelection_PointerMoved;

            scrollViewer.ViewChanged -= ScrollViewer_ViewChanged;
            uiElement.ReleasePointerCapture(e.Pointer);
            if (selectionChanged != null)
            {
                // Restore and trigger SelectionChanged event
                uiElement.SelectionChanged -= selectionChanged;
                uiElement.SelectionChanged += selectionChanged;
                if (prevSelectedItems == null || !uiElement.SelectedItems.SequenceEqual(prevSelectedItems))
                {
                    // Trigger SelectionChanged event if the selection has changed
                    selectionChanged(sender, null);
                }
            }
            if (selectionState == SelectionState.Active || e.OriginalSource is ListViewBase)
            {
                // Always trigger SelectionEnded to focus the file list when clicking on the empty space (#2977)
                OnSelectionEnded();
            }

            selectionStrategy = null;
            selectionState    = SelectionState.Inactive;

            e.Handled = true;
        }
        private void RectangleSelection_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            itemsPosition.Clear();
            dataGridRows.Clear();
            DependencyObjectHelpers.FindChildren <DataGridRow>(dataGridRows, uiElement);                                     // Find visible/loaded rows
            prevSelectedItems = uiElement.SelectedItems.Cast <object>().ToList();                                            // Save current selected items
            originDragPoint   = new Point(e.GetCurrentPoint(uiElement).Position.X, e.GetCurrentPoint(uiElement).Position.Y); // Initial drag point relative to the topleft corner
            var verticalOffset = (scrollBar?.Value ?? 0) - uiElement.ColumnHeaderHeight;

            originDragPoint.Y += verticalOffset; // Initial drag point relative to the top of the list (considering scrolled offset)
            if (!e.GetCurrentPoint(uiElement).Properties.IsLeftButtonPressed || e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch)
            {
                // Trigger only on left click, do not trigger with touch
                return;
            }

            var clickedRow = DependencyObjectHelpers.FindParent <DataGridRow>(e.OriginalSource as DependencyObject);

            if (clickedRow != null && uiElement.SelectedItems.Contains(clickedRow.DataContext))
            {
                // If the item under the pointer is selected do not trigger selection rectangle
                return;
            }

            var selectedItems = new GenericItemsCollection <object>(uiElement.SelectedItems);

            selectionStrategy = e.KeyModifiers.HasFlag(VirtualKeyModifiers.Control) ?
                                new InvertPreviousItemSelectionStrategy(selectedItems, prevSelectedItems) :
                                e.KeyModifiers.HasFlag(VirtualKeyModifiers.Shift) ?
                                (ItemSelectionStrategy) new ExtendPreviousItemSelectionStrategy(selectedItems, prevSelectedItems) :
                                new IgnorePreviousItemSelectionStrategy(selectedItems);

            if (clickedRow == null)
            {
                // If user click outside, reset selection
                if (uiElement.CurrentColumn != null)
                {
                    uiElement.CancelEdit();
                }
                DeselectGridCell();
                selectionStrategy.HandleNoItemSelected();
            }

            uiElement.PointerMoved -= RectangleSelection_PointerMoved;
            uiElement.PointerMoved += RectangleSelection_PointerMoved;
            if (selectionChanged != null)
            {
                // Unsunscribe from SelectionChanged event for performance
                uiElement.SelectionChanged -= selectionChanged;
            }
            uiElement.CapturePointer(e.Pointer);
            selectionState = SelectionState.Starting;
        }