コード例 #1
0
        private void OnOwnerMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            FinishDrag();

            if (!ValidateSelectionDragSource(e.OriginalSource) || AdornerLayer.GetAdornerLayer(Owner) == null)
            {
                return;
            }

            Owner.AddHandler(UIElement.MouseMoveEvent, new MouseEventHandler(OnOwnerMouseMove), true);
            Owner.LostMouseCapture += OnOwnerLostMouseCapture;
            Owner.PreviewMouseUp   += OnOwnerPreviewMouseLeftButtonUp;
            Owner.LostFocus        += OnOwnerLostFocus;
            SelectionBoxAdorner     = CreateSelectionBoxAdorner(Owner, SelectionBox, e.GetPosition(Owner));
        }
コード例 #2
0
        private void FinishDrag()
        {
            Owner.RemoveHandler(UIElement.MouseMoveEvent, new MouseEventHandler(OnOwnerMouseMove));
            Owner.LostMouseCapture -= OnOwnerLostMouseCapture;
            Owner.PreviewMouseUp   -= OnOwnerPreviewMouseLeftButtonUp;
            Owner.LostFocus        -= OnOwnerLostFocus;

            if (SelectionBoxAdorner != null)
            {
                AdornerLayer parentAdorner = AdornerLayer.GetAdornerLayer(Owner);
                if (parentAdorner != null)
                {
                    parentAdorner.Remove(SelectionBoxAdorner);
                }
                SelectionBoxAdorner.IsRemoved = true;
                SelectionBoxAdorner           = null;
            }
            IsSelecting = false;
            Owner.ReleaseMouseCapture();
        }