Ejemplo n.º 1
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            var thumbAndSubscription = SelectAndSubscribeToThumb();

            _templateSubscriptions.Disposable = thumbAndSubscription.Item2;

            if (_seizeDragWithTemplate && thumbAndSubscription.Item1 != null)
            {
                _isTemplateThumbWithMouseAfterSeize = true;
                Mouse.AddLostMouseCaptureHandler(this, LostMouseAfterSeizeHandler);
                if (_dragSeizedContinuation != null)
                {
                    _dragSeizedContinuation(this);
                }
                _dragSeizedContinuation = null;

                Dispatcher.BeginInvoke(new Action(() => thumbAndSubscription.Item1.RaiseEvent(new MouseButtonEventArgs(InputManager.Current.PrimaryMouseDevice,
                                                                                                                       0,
                                                                                                                       MouseButton.Left)
                {
                    RoutedEvent = MouseLeftButtonDownEvent
                })));
            }
            _seizeDragWithTemplate = false;
        }
Ejemplo n.º 2
0
 private void PopupOpened(object sender, EventArgs e)
 {
     Mouse.Capture(this, CaptureMode.SubTree);
     // Mouse capture can be lost on 'this' when the user clicks on the scroll bar, which can cause
     // OutsideCapturedElementHandler to never be called. If we monitor the popup for lost mouse capture
     // (which the popup gains on mouse down of the scroll bar), then we can recapture the mouse at that point
     // to cause OutsideCapturedElementHandler to be called again.
     Mouse.AddLostMouseCaptureHandler(this._popup, this.LostMouseCaptureHandler);
 }
Ejemplo n.º 3
0
 public MainWindow()
 {
     InitializeComponent();
     _captureElement = this;
     Mouse.AddGotMouseCaptureHandler((DependencyObject)_captureElement, stackPanel1_GotLostMouseCapture);
     Mouse.AddLostMouseCaptureHandler((DependencyObject)_captureElement, stackPanel1_GotLostMouseCapture);
     Mouse.Capture(_captureElement);
     MouseCaptured = Mouse.Captured != null;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Defers the specified action until the application is idle.
 /// </summary>
 /// <param name="dispatcher">The dispatcher.</param>
 /// <param name="action">The action.</param>
 public static void Defer(Dispatcher dispatcher, Action action)
 {
     var element = Mouse.Captured as DependencyObject;
     if (element != null)
     {
         // Mouse interaction in progress.
         // --> Run the specified action when the mouse interaction is complete.
         MouseEventHandler handler = null;
         handler = (sender, args) =>
         {
             // ReSharper disable once AssignNullToNotNullAttribute
             Mouse.RemoveLostMouseCaptureHandler(element, handler);
             action();
         };
         Mouse.AddLostMouseCaptureHandler(element, handler);
     }
     else
     {
         // Run the specified action when the application is idle.
         dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, action);
     }
 }
Ejemplo n.º 5
0
        private static void OnIsSubmenuOpenChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            SplitButton splitButton = sender as SplitButton;

            if ((bool)args.NewValue)
            {
                openSplitButton = splitButton;

                // Handle keyboard events as long as the popup is displayed
                var window = Window.GetWindow(splitButton);
                window.PreviewKeyDown += OnPreviewKeyDown;

                if (Mouse.Captured != splitButton)
                {
                    Mouse.Capture(splitButton, CaptureMode.SubTree);
                    Mouse.AddLostMouseCaptureHandler(splitButton, OnLostMouseCapture);
                }
            }
            else
            {
                // Remove popup keyboard handler
                var window = Window.GetWindow(splitButton);
                window.PreviewKeyDown -= OnPreviewKeyDown;

                openSplitButton = null;

                if (Mouse.Captured == splitButton)
                {
                    Mouse.Capture(null);
                }

                if (splitButton.IsKeyboardFocused)
                {
                    splitButton.Focus();
                }
            }
        }