예제 #1
0
        public void Hide(ContentDialogResult result)
        {
            _result = result;

            if (result == ContentDialogResult.Primary)
            {
                var button = GetTemplateChild("PrimaryButton") as Button;
                if (button != null)
                {
                    var invoke = new ButtonAutomationPeer(button) as IInvokeProvider;
                    if (invoke != null)
                    {
                        invoke.Invoke();
                        return;
                    }
                }
            }
            else if (result == ContentDialogResult.Secondary)
            {
                var button = GetTemplateChild("SecondaryButton") as Button;
                if (button != null)
                {
                    var invoke = new ButtonAutomationPeer(button) as IInvokeProvider;
                    if (invoke != null)
                    {
                        invoke.Invoke();
                        return;
                    }
                }
            }

            Hide();
        }
        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);
        }
예제 #3
0
        public void CopiesTextCorrectly()
        {
            try
            {
                CodeSample           codeSampleNormal = (CodeSample)ControlsTestPage.Instance.FindName("CodeSampleNormal");
                ButtonAutomationPeer copyButton       = new ButtonAutomationPeer((Button)codeSampleNormal.FindName("CopyButton"));

                copyButton.Invoke();
                Assert.AreEqual("Code", GetClipBoardText());

                CodeSample codeSampleHighlightingEnabled = (CodeSample)ControlsTestPage.Instance.FindName("CodeSampleWithHighlighting");
                copyButton = new ButtonAutomationPeer((Button)codeSampleHighlightingEnabled.FindName("CopyButton"));

                copyButton.Invoke();

                Assert.AreEqual("<Code />", GetClipBoardText());
            }
            catch (UnauthorizedAccessException)
            {
                // Pasting to clipboard is not allowed while app is in background
#pragma warning disable CA1303 // Do not pass literals as localized parameters
                Console.WriteLine("Test CopiesTextCorrectly was not run as app is not in foreground");
#pragma warning restore CA1303 // Do not pass literals as localized parameters
            }
        }
예제 #4
0
 private void FilterTextBox_OnKeyUp(object sender, KeyRoutedEventArgs eventArgs)
 {
     if (eventArgs.Key == VirtualKey.Escape)
     {
         var buttonAutomationPeer = new ButtonAutomationPeer(DoneButton);
         buttonAutomationPeer.Invoke();
     }
 }
예제 #5
0
        private void Initialize()
        {
            m_Path = @"C:\Users\" + System.Environment.UserName + @"\Downloads";

            UpdateDirectoryTextBox(m_Path);
            var provider = new ButtonAutomationPeer(Button_GetInfo) as IInvokeProvider;

            provider.Invoke();
        }
예제 #6
0
파일: clsCtrl.cs 프로젝트: SnyUmd/wpf_ctrl
        //***************************************************************
        //WinFormsでいうPerformClickを実行.
        //
        //■参照の追加が必要
        // PresentationCore
        // PresentationFramework
        // UIAutomationProvider
        // WindowsBase
        //
        //   System.Windows.Automation.Peers
        //   System.Windows.Automation.Provider
        // 名前空間が必要。
        //
        // IInvokeProviderインターフェースは、UIAutomationProvider.dll
        // の参照設定が追加で必要となる。
        //
        //***************************************************************
        public void PerformClick0(Button button)
        {
            if (button == null)
            {
                throw new ArgumentNullException("button");
            }

            var provider = new ButtonAutomationPeer(button) as IInvokeProvider;

            provider.Invoke();
        }
예제 #7
0
        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            switch (msg)
            {
            case WM_NCHITTEST:
                try
                {
                    int    xl    = lParam.ToInt32() & 0xffff;
                    int    yl    = lParam.ToInt32() >> 16;
                    Button _btn1 = GetCommandButton();
                    var    rectx = new Rect(_btn1.PointToScreen(
                                                new Point()),
                                            new Size(_btn1.Width * DPI_SCALE, _btn1.Height * DPI_SCALE));
                    if (rectx.Contains(new Point(xl, yl)))
                    {
                        handled          = true;
                        _btn1.Background = _bgMouseHover;
                    }
                    else
                    {
                        _btn1.Background = _bgNormal;
                    }
                    return(new IntPtr(HTMAXBUTTON));
                }
                catch (OverflowException)
                {
                    handled = true;
                }
                break;

            case WM_NCLBUTTONDOWN:
                int    x     = lParam.ToInt32() & 0xffff;
                int    y     = lParam.ToInt32() >> 16;
                Button _btn2 = GetCommandButton();
                var    rect  = new Rect(_btn2.PointToScreen(
                                            new Point()),
                                        new Size(_btn2.Width * DPI_SCALE, _btn2.Height * DPI_SCALE));
                if (rect.Contains(new Point(x, y)))
                {
                    handled = true;
                    IInvokeProvider invokeProv = new ButtonAutomationPeer(_btn2).GetPattern(PatternInterface.Invoke) as IInvokeProvider;
                    invokeProv?.Invoke();
                }
                break;

            default:
                handled = false;
                break;
            }
            return(IntPtr.Zero);
        }
예제 #8
0
        private void TimerGaze_Tick(object sender, object e)
        {
            // Increment progress bar.
            GazeRadialProgressBar.Value += 1;

            // If progress bar reaches maximum value, reset and relocate.
            if (GazeRadialProgressBar.Value >= 100)
            {
                //SetGazeTargetLocation();
                Button b = focusElement as Button;

                if (b != null)
                {
                    ButtonAutomationPeer peer = new ButtonAutomationPeer(b);
                    peer.Invoke();
                }
                GazeRadialProgressBar.Value = 0;
            }
        }
예제 #9
0
        public MainWindow()
        {
            const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase;

            InitializeComponent();
            SettingsLoad();

            Icon              = _idleIcon;
            _timer.Tick      += TimerOnTick;
            _timerFlash.Tick += TimerFlashOnTick;

            foreach (var arg in Regex.Matches(Environment.CommandLine, @"-(?<key>\w+)\s+(""(?<value>[^""]*)""|(?<value>\S+))").OfType <Match>()
                     .Select(m => new { Obj = GetType().GetField(m.Groups["key"].Value, flags)?.GetValue(this), m.Groups["value"].Value })
                     .Where(m => m.Obj != null))
            {
                bool value;

                if (arg.Obj is PasswordBox)
                {
                    ((PasswordBox)arg.Obj).Password = arg.Value;
                }
                else if (arg.Obj is CheckBox && bool.TryParse(arg.Value, out value))
                {
                    ((CheckBox)arg.Obj).IsChecked = value;
                }
                else if (arg.Obj is TextBox)
                {
                    ((TextBox)arg.Obj).Text = arg.Value;
                }
                else if (arg.Obj is Button && Compare(arg.Value, "Click", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    var invokeProv = new ButtonAutomationPeer((Button)arg.Obj).GetPattern(PatternInterface.Invoke) as IInvokeProvider;
                    invokeProv?.Invoke();
                }
            }
        }