예제 #1
0
        /// <summary>Selects the <c>TreeViewItem</c> when right clicking on the <c>TreeView</c>.</summary>
        /// <param name="sender">The object that called the event.</param>
        /// <param name="e">The <c>System.Windows.Input.MouseButtonEventArgs</c> instance containing the event data.</param>
        void SelectedItemOnRightClick(object sender, MouseButtonEventArgs e)
        {
            var           tv      = (TreeView)sender;
            IInputElement element = tv.InputHitTest(e.GetPosition(tv));

            while (!((element is TreeView) || element == null))
            {
                if (element is TreeViewItem)
                {
                    break;
                }

                if (!(element is FrameworkElement))
                {
                    break;
                }

                var fe = (FrameworkElement)element;
                element = (IInputElement)(fe.Parent ?? fe.TemplatedParent);
            }

            if (!(element is TreeViewItem))
            {
                return;
            }

            element.Focus();
            e.Handled = true;
        }
예제 #2
0
        private void Grbl_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            var grbl = sender as GrblViewModel;

            switch (e.PropertyName)
            {
            case nameof(GrblViewModel.IsJobRunning):
                foreach (TabItem tabitem in tab.Items)
                {
                    tabitem.IsEnabled = !grbl.IsJobRunning || tabitem == tab.SelectedItem;
                }
                if (!grbl.IsJobRunning && focusedControl != null)
                {
                    Application.Current.Dispatcher.BeginInvoke(new System.Action(() =>
                    {
                        focusedControl.Focus();
                        focusedControl = null;
                    }), DispatcherPriority.Render);
                }
                break;

            case nameof(GrblViewModel.Position):
                DisplayPosition(grbl);
                break;

            case nameof(GrblViewModel.Signals):
                probeTriggered    = grbl.Signals.Value.HasFlag(Signals.Probe);
                probeDisconnected = grbl.Signals.Value.HasFlag(Signals.ProbeDisconnected);
                DisplayPosition(grbl);
                break;
            }
        }
예제 #3
0
        private void ProcessRequest()
        {
            // Create a background task for your work
            var task = Task.Factory.StartNew(InvokeTenonService);

            // When it completes, have it hide (on the UI thread), Spinner element
            task.ContinueWith(t =>
            {
                Spinner.Visibility               = Visibility.Hidden;
                this.BtnCancel.Content           = contents.OKMessage;
                this.BtnValidate.Visibility      = Visibility.Hidden;
                this.processingtext.Visibility   = Visibility.Hidden;
                this.ErrorPlaceholder.Visibility = Visibility.Visible;
                this.ErrorPlaceholder.Text       = TenonAccessibilityCheckerPackage.TenonErrorMessage;
                this.ErrorPlaceholder.Foreground = TenonAccessibilityCheckerPackage.TenonStatusCode == contents.TenonApiResponseSuccess ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Red);

                // Sets the focused element in focusScope1 focusScope1 is a StackPanel.
                FocusManager.SetFocusedElement(ErrorPlaceholder, ErrorPlaceholder);

                // Gets the focused element for focusScope 1
                IInputElement focusedElement = FocusManager.GetFocusedElement(ErrorPlaceholder);
                focusedElement.Focus();
            },
                              TaskScheduler.FromCurrentSynchronizationContext()
                              );
        }
예제 #4
0
        private void MouseDown(IMouseDevice device, IVisual visual, Point p)
        {
            IVisual hit = visual.GetVisualAt(p);

            if (hit != null)
            {
                IInteractive source = this.GetSource(hit);

                if (source != null)
                {
                    source.RaiseEvent(new PointerEventArgs
                    {
                        Device         = this,
                        RoutedEvent    = InputElement.PointerPressedEvent,
                        OriginalSource = source,
                        Source         = source,
                    });
                }

                IInputElement focusable = this.GetFocusable(hit);

                if (focusable != null && focusable.Focusable)
                {
                    focusable.Focus();
                }
            }
        }
예제 #5
0
		public void Focus(IInputElement element) {
			Debug.Assert(element != null && element.Focusable);
			if (element == null || !element.Focusable)
				return;
			if (CanFocus)
				element.Focus();
		}
예제 #6
0
        private static void window_Activated(object sender, EventArgs e)
        {
            var           window = (Window)sender;
            IInputElement elem   = GetInitialFocusElement(window);

            elem.Focus();
        }
예제 #7
0
 /// <summary>
 /// Method sets the Control Focus and <see cref="Keyboard.FocusedElement"/>
 /// to either switch <see cref="ContentOn"/> or <see cref="ContentOff"/> as
 /// determined by <paramref name="focusContentOn"/>.
 ///
 /// This method of setting the focus requires a Focusable element
 /// (eg.: Grid Focusable="true") to be present inside the switch.
 /// </summary>
 /// <param name="focusContentOn"></param>
 /// <returns></returns>
 public async Task FocusSwitchAsync(bool focusContentOn = true)
 {
     if (focusContentOn == true)
     {
         await this.Dispatcher.BeginInvoke(new Action(() =>
         {
             // Focus the newly switched UI element (requires Focusable="True")
             IInputElement inpcontrol = this.ContentOn as IInputElement;
             if (inpcontrol != null)
             {
                 Keyboard.Focus(inpcontrol);
                 inpcontrol.Focus();
             }
         }), System.Windows.Threading.DispatcherPriority.Background);
     }
     else
     {
         await this.Dispatcher.BeginInvoke(new Action(() =>
         {
             IInputElement inpcontrol = this.ContentOff as IInputElement;
             if (inpcontrol != null)
             {
                 Keyboard.Focus(inpcontrol);
                 inpcontrol.Focus();
             }
         }), System.Windows.Threading.DispatcherPriority.Background);
     }
 }
        private void ListBox_Step_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.F6)
            {
                e.Handled = true;
                Queue <DependencyObject> objqueue = new Queue <DependencyObject>();
                objqueue.Enqueue(ContentFrame.Content as DependencyObject);

                while (objqueue.Count > 0)
                {
                    var           o   = objqueue.Dequeue();
                    IInputElement ele = o as IInputElement;
                    if (ele.Focusable)
                    {
                        ele.Focus();
                        break;
                    }
                    foreach (Object child in LogicalTreeHelper.GetChildren(o))
                    {
                        var childobj = child as DependencyObject;
                        if (childobj != null)
                        {
                            objqueue.Enqueue(childobj);
                        }
                    }
                }
            }
        }
예제 #9
0
        private static void Control_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var control = (FrameworkElement)sender;

            if (control.IsVisible)
            {
                lastFocus = Keyboard.FocusedElement;
                if (control.Focusable && control.IsVisible)
                {
                    control.Focus();
                }
                else
                {
                    foreach (var child in ElementTreeHelper.FindVisualChildren <FrameworkElement>(control))
                    {
                        if (child.Focusable && child.IsVisible)
                        {
                            child.Focus();
                            return;
                        }
                    }
                }
            }
            else
            {
                if (lastFocus != null)
                {
                    lastFocus.Focus();
                }
            }
        }
예제 #10
0
        private void treeViewReports_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            IInputElement element = treeViewReports.InputHitTest(e.GetPosition(treeViewReports));

            while (!((element is TreeView) || element == null))
            {
                if (element is TreeViewItem)
                {
                    break;
                }

                if (element is FrameworkElement)
                {
                    FrameworkElement fe = (FrameworkElement)element;
                    element = (IInputElement)(fe.Parent ?? fe.TemplatedParent);
                }
                else
                {
                    break;
                }
            }
            if (element is TreeViewItem)
            {
                element.Focus();
                e.Handled = true;
            }
        }
예제 #11
0
        private static void SetFocus(IInputElement senderAsInput)
        {
            try
            {
                if (senderAsInput is FrameworkElement fe)
                {
                    fe.BringIntoView();
                }

                Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Input, (Action)(() =>
                {
                    senderAsInput.Focus();
                    Keyboard.PrimaryDevice.Focus(senderAsInput);
                }));

                //        //This hack works arround a bug in datepicker -- focusing a datepicker does not focus the textbox
                if (senderAsInput is DatePicker)
                {
                    var eventArgs = new KeyEventArgs(Keyboard.PrimaryDevice,
                                                     Keyboard.PrimaryDevice.ActiveSource ?? PresentationSource.FromVisual(senderAsInput as Visual),
                                                     0,
                                                     Key.Up);
                    eventArgs.RoutedEvent = DatePicker.KeyDownEvent;

                    Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() => senderAsInput.RaiseEvent(eventArgs)), DispatcherPriority.ApplicationIdle);
                }

                (senderAsInput as TextBox)?.SelectAll();
            }
            catch (InvalidOperationException)
            {
            }
        }
예제 #12
0
        private void TreeViewItem_PreviewMouseRightButtonDown(Object sender, MouseEventArgs e)
        {
            TreeView      treeView = PART_treeView;
            IInputElement element  = treeView.InputHitTest(e.GetPosition(treeView));

            while (!((element is TreeView) || element == null))
            {
                if (element is TreeViewItem)
                {
                    break;
                }

                if (element is FrameworkElement)
                {
                    FrameworkElement fe = (FrameworkElement)element;
                    element = (IInputElement)(fe.Parent ?? fe.TemplatedParent);
                }
                else
                {
                    break;
                }
            }

            if (element is TreeViewItem)
            {
                element.Focus();
                e.Handled = true;
            }
        }
        private void TreeView_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            var           tv      = (TreeView)sender;
            IInputElement element = tv.InputHitTest(e.GetPosition(tv));

            while (!((element is TreeView) || element == null))
            {
                if (element is TreeViewItem)
                {
                    break;
                }

                if (element is FrameworkElement)
                {
                    var fe = (FrameworkElement)element;
                    element = (IInputElement)(fe.Parent ?? fe.TemplatedParent);
                }
                else if (element is FrameworkContentElement)
                {
                    var fe = (FrameworkContentElement)element;
                    element = (IInputElement)fe.Parent;
                }
                else
                {
                    break;
                }
            }
            if (element is TreeViewItem)
            {
                element.Focus();
                e.Handled = true;
            }
        }
        /// <summary>
        /// Called when a key is pressed in the owner window.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        protected virtual void OnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.LeftAlt)
            {
                _altIsDown = true;

                if (MainMenu == null || !MainMenu.IsOpen)
                {
                    // TODO: Use FocusScopes to store the current element and restore it when context menu is closed.
                    // Save currently focused input element.
                    _restoreFocusElement = FocusManager.Instance.Current;

                    // When Alt is pressed without a main menu, or with a closed main menu, show
                    // access key markers in the window (i.e. "_File").
                    _owner.ShowAccessKeys = _showingAccessKeys = true;
                }
                else
                {
                    // If the Alt key is pressed and the main menu is open, close the main menu.
                    CloseMenu();
                    _ignoreAltUp = true;

                    _restoreFocusElement?.Focus();
                    _restoreFocusElement = null;
                }

                // We always handle the Alt key.
                e.Handled = true;
            }
            else if (_altIsDown)
            {
                _ignoreAltUp = true;
            }
        }
예제 #15
0
        /// <summary>
        /// select items on right click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tree_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            IInputElement element = _tree.InputHitTest(e.GetPosition(_tree));

            while (!((element is System.Windows.Controls.TreeView) || element == null))
            {
                if (element is TreeViewItem)
                {
                    break;
                }

                if (element is FrameworkElement)
                {
                    FrameworkElement fe = (FrameworkElement)element;
                    element = (IInputElement)(fe.Parent ?? fe.TemplatedParent);
                }
                else
                {
                    break;
                }
            }
            if (element is TreeViewItem)
            {
                element.Focus();
//                e.Handled = true;
            }
        }
예제 #16
0
 protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
 {
     base.OnDetachedFromVisualTree(e);
     Debug.WriteLine("Detached from visual tree!");
     LastFocusedElement.Focus();
     ContentDialog.IsShowingDialog = false;
 }
예제 #17
0
 private void SetFocus(IInputElement control)
 {
     Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
     {
         control.Focus();
         Keyboard.Focus(control);
     }));
 }
예제 #18
0
 void RestoreFocuses()
 {
     if (backUpFocusedElement != null)
     {
         backUpFocusedElement.Focus();
     }
     ribbon.Focusable = false;
 }
        public void Execute(object parameter)
        {
            IInputElement target = parameter as IInputElement;

            if (target != null)
            {
                target.Focus();
            }
        }
예제 #20
0
 void RestoreFocuses()
 {
     if (backUpFocusedElement != null)
     {
         if (RibbonPopup.GetActivePopup() == null)
         {
             backUpFocusedElement.Focus();
         }
     }
     ribbon.Focusable = false;
 }
예제 #21
0
 public virtual void Close(object sender, ExecutedRoutedEventArgs e)
 {
     this.Visibility = Visibility.Hidden;
     this.SetValue(IsOpenedProperty, false);
     OnClosed(EventArgs.Empty);
     if (backFocusedControl != null)
     {
         backFocusedControl.Focus();
     }
     //ModalSpace.ShowModal(this, false);
 }
예제 #22
0
 public void Focus(IInputElement element)
 {
     Debug.Assert(element != null && element.Focusable);
     if (element == null || !element.Focusable)
     {
         return;
     }
     if (CanFocus)
     {
         element.Focus();
     }
 }
예제 #23
0
        public static void MoveKeyboardFocusNextThenBack()
        {
            IInputElement inputElement = Keyboard.FocusedElement;

            TraversalRequest traversalRequestNext = new TraversalRequest(FocusNavigationDirection.Next);
            UIElement        keyboardFocus        = Keyboard.FocusedElement as UIElement;

            if (keyboardFocus != null)
            {
                keyboardFocus.MoveFocus(traversalRequestNext);
                inputElement.Focus();
            }
        }
예제 #24
0
        private void OnCollapsed(object sender, EventArgs e)
        {
            Visibility = Visibility.Collapsed;

            RaiseEvent(new RoutedEventArgs(CollapsedEvent));

            if (IsOpen)
            {
                IsOpen = false;
            }

            Dispatcher.BeginInvoke(((Action)(() => previouslyFocusedElement?.Focus())), DispatcherPriority.Input);
        }
예제 #25
0
        /// <summary>
        /// Class constructor
        /// </summary>
        public EditableList()
        {
            InitializeComponent();

            // once the element tree is loaded, focus the first listbox item
            Dispatcher.BeginInvoke(DispatcherPriority.Loaded, (ThreadStart) delegate()
            {
                IInputElement container = lb.ItemContainerGenerator.ContainerFromIndex(0) as IInputElement;
                if (container != null)
                {
                    container.Focus();
                }
            });
        }
예제 #26
0
        protected override void OnUnloaded()
        {
            if (_previouslyFocusedElement != null)
            {
                if (Keyboard.FocusedElement is Visual element && element.IsDescendantOf(View))
                {
                    _previouslyFocusedElement.Focus();
                }

                _previouslyFocusedElement = null;
            }

            base.OnUnloaded();
        }
예제 #27
0
        /// <summary>
        /// Focuses <paramref name="element"/>
        /// </summary>
        /// <param name="element">Element to focus</param>
        /// <param name="calledAfterFocus">Delegate that gets called once the element has gotten focus. Can be null.</param>
        public static void Focus(IInputElement?element, Action?calledAfterFocus = null)
        {
            var uiElem  = element as UIElement;
            var fwkElem = element as FrameworkElement;

            if (uiElem is null || (fwkElem is not null && fwkElem.IsLoaded && fwkElem.IsVisible) || (fwkElem is null && uiElem.IsVisible))
            {
                element?.Focus();
                calledAfterFocus?.Invoke();
                return;
            }

            new FocusHelper(uiElem, calledAfterFocus);
        }
예제 #28
0
        /// <summary>
        /// Gets the active keyboardstate.
        /// </summary>
        /// <returns></returns>
        public KeyboardState GetState()
        {
            if (_focusElement.IsMouseDirectlyOver && Keyboard.FocusedElement != _focusElement)
            {
                // we assume the user wants keyboard input into the control when his mouse is over it
                // in order for the events to register we must focus it

                if (WindowHelper.IsControlOnActiveWindow(_focusElement))
                {
                    // however, only focus if we are the active window, otherwise the window will become active and pop into foreground just by hovering the mouse over the game panel
                    _focusElement.Focus();
                }
            }
            return(new KeyboardState(GetKeys(_focusElement)));
        }
예제 #29
0
        private void SelectTextBox(TextBox textBox, int start, int length)
        {
            IInputElement old = Keyboard.FocusedElement;

            try
            {
                textBox.Focus();
                textBox.Select(start, length);
                AdjustControlPosition(textBox);
            }
            finally
            {
                old.Focus();
            }
        }
예제 #30
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            if (stepFrame.Content == null)
            {
                Services.NavigationService.InitializeSecondaryFrame(stepFrame, WizardNavigation.Current.CurrentStep.GetPage());
                sequentialFlow.FocusFirstStep();
            }

            if (_focusedElement != null)
            {
                _focusedElement.Focus();
                Keyboard.Focus(_focusedElement);
            }

            Services.NavigationService.SubscribeEventHandlers();
            PreviewGotKeyboardFocus += OnPreviewGotKeyboardFocus;
        }
        private void ActionMenuItemSelectedEventHandler(object sender, MenuItemSelectedEventArgs e)
        {
            ShellDrillDownMenuItem action = e.SelectedItem as ShellDrillDownMenuItem;

            if ((action != null))
            {
                IInputElement element = FocusManager.GetFocusedElement(Application.Current.MainWindow);
                ((UIElement)e.Source).Focus();

                if (element != null)
                {
                    element.Focus();
                }

                Presenter.ExecuteAction(action);
            }
        }