Exemplo n.º 1
0
 public void SimClick(ButtonBase element)
 {
     element.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left)
     {
         RoutedEvent = Control.MouseDownEvent,
         Source      = element,
     });
     element.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left)
     {
         RoutedEvent = Control.MouseUpEvent,
         Source      = element,
     });
 }
        public static async Task <bool> SimulateClickAsync(this ButtonBase button, JoinableTaskFactory joinableTaskFactory)
        {
            await joinableTaskFactory.SwitchToMainThreadAsync();

            if (!button.IsEnabled || !button.IsVisible)
            {
                return(false);
            }

            if (button is RadioButton radioButton)
            {
                ISelectionItemProvider peer = new RadioButtonAutomationPeer(radioButton);
                peer.Select();
            }
            else if (button is Button button2)
            {
                IInvokeProvider peer = new ButtonAutomationPeer(button2);
                peer.Invoke();
            }
            else
            {
                button.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
                ExecuteCommandSource(button, true);
            }

            // Wait for changes to propagate
            await Task.Yield();

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Refocuses the photo viewer control when the button is pressed via *mouse* click.
        /// </summary>
        /// <param name="e">Event arguments describing the mouse event.</param>
        protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonUp(e);

            ButtonBase button = e.Source as ButtonBase;

            if (button != null && this.FocusTarget != null)
            {
                // ManuallyAddContact raise the event on the button since focusing another control breaks the original event routing.
                MouseButtonEventArgs mouseEventArgs = new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left);
                mouseEventArgs.RoutedEvent = Mouse.MouseUpEvent;
                button.RaiseEvent(mouseEventArgs);

                this.FocusTarget.Focus();
            }
        }
Exemplo n.º 4
0
        bool RaiseButtonClick(UIElement element)
        {
            ButtonBase button = element == null ? null : LayoutHelper.FindParentObject <ButtonBase>(element);

            if (button == null)
            {
                return(false);
            }
            RoutedEventArgs click = new RoutedEventArgs(ButtonBase.ClickEvent, button);

            button.RaiseEvent(click);
            ICommand command = button.Command;

            if (command != null && command.CanExecute(button.CommandParameter) && button.IsEnabled)
            {
                command.Execute(button.CommandParameter);
            }
            return(true);
        }
Exemplo n.º 5
0
        private void OnStylusStuff(object sender, StylusEventArgs args)
        {
            if (args.RoutedEvent == UIElement.StylusUpEvent ||
                (args.RoutedEvent == UIElement.StylusDownEvent && args.Source == null) ||
                (args.RoutedEvent == UIElement.StylusMoveEvent && args.Source == null && args.InAir))
            {
                MultitouchWindow.RemoveStylusListener(args.StylusDevice, _attachedElement, OnStylusStuff);

                if (!_downpoint.ContainsKey(args.StylusDevice.Id))
                {
                    return;
                }

                //if (args.OriginalSource != _attachedElement) return;

                args.Handled = true;

                Point  current = args.GetPosition(args.Device.ActiveSource.RootVisual as IInputElement);
                Vector jitter  = Point.Subtract(current, _downpoint[args.StylusDevice.Id]);
                if (jitter.Length < Threshold)
                {
                    if (Tap != null)
                    {
                        Tap.Invoke(_attachedElement, new TapEventArgs(args.StylusDevice, jitter));
                    }

                    if (_button != null)
                    {
                        _button.SetValue(TapBehavior.IsPressedProperty, true);
                        _button.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
                        ExecuteCommandSource(_button);
                    }

                    if ((args.Timestamp - _lasttap) < DoubleTapDelay.TotalMilliseconds && DoubleTap != null)
                    {
                        DoubleTap.Invoke(_attachedElement, new TapEventArgs(args.StylusDevice, jitter));
                    }

                    if (_attachedElement is Control)
                    {
                        ((Control)_attachedElement).RaiseEvent(
                            new MouseButtonEventArgs(Mouse.PrimaryDevice, args.Timestamp,
                                                     MouseButton.Left, args.StylusDevice)
                        {
                            RoutedEvent = Control.MouseDoubleClickEvent
                        });
                    }

                    _lasttap = args.Timestamp;
                }
            }
            else if (args.RoutedEvent == UIElement.StylusDownEvent)
            {
                MultitouchWindow.AddStylusListener(args.StylusDevice, _attachedElement, OnStylusStuff);
                _downpoint[args.StylusDevice.Id] = args.GetPosition(args.Device.ActiveSource.RootVisual as IInputElement);

                if (_button != null)
                {
                    _button.SetValue(TapBehavior.IsPressedProperty, true);
                }
            }
            else if (args.RoutedEvent == UIElement.StylusMoveEvent)
            {
                if (!_downpoint.ContainsKey(args.StylusDevice.Id))
                {
                    return;
                }

                Point current = args.GetPosition(args.Device.ActiveSource.RootVisual as IInputElement);
                if (Point.Subtract(current, _downpoint[args.StylusDevice.Id]).Length > Threshold)
                {
                    _downpoint.Remove(args.StylusDevice.Id);

                    if (_button != null)
                    {
                        _button.SetValue(TapBehavior.IsPressedProperty, false);
                    }
                }
            }
        }
 public static void Click(ButtonBase button)
 {
     button.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
 }
Exemplo n.º 7
0
 public static void RaiseClickEvent(this ButtonBase button)
 => button.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent, button));
Exemplo n.º 8
0
 public void InternalClick(ButtonBase element)
 {
     Contract.Assert(element != null);
     AssertInputable(element);
     element.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent, element));
 }
Exemplo n.º 9
0
 public static void xPerformClick(this ButtonBase btn)
 {
     btn.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
 }