/// <summary>
 /// Handles the <see cref="WUX.Hosting.DesktopWindowXamlSource.TakeFocusRequested" /> event.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="WUX.Hosting.DesktopWindowXamlSourceTakeFocusRequestedEventArgs"/> instance containing the event data.</param>
 private void OnTakeFocusRequested(object sender, WUX.Hosting.DesktopWindowXamlSourceTakeFocusRequestedEventArgs e)
 {
     if (_lastFocusRequest == e.Request.CorrelationId)
     {
         // If we've arrived at this point, then focus is being move back to us
         // therefore, we should complete the operation to avoid an infinite recursion
         // by "Restoring" the focus back to us under a new correctationId
         var newRequest = new WUX.Hosting.XamlSourceFocusNavigationRequest(
             WUX.Hosting.XamlSourceFocusNavigationReason.Restore);
         _xamlSource.NavigateFocus(newRequest);
     }
     else
     {
         _onTakeFocusRequested = true;
         try
         {
             // Last focus request is not initiated by us, so continue
             _lastFocusRequest = e.Request.CorrelationId;
             var direction = MapReasonToDirection[e.Request.Reason];
             var request   = new System.Windows.Input.TraversalRequest(direction);
             MoveFocus(request);
         }
         finally
         {
             _onTakeFocusRequested = false;
         }
     }
 }
        /// <summary>
        /// Process Tab from host framework
        /// </summary>
        /// <param name="request"><see cref="System.Windows.Input.TraversalRequest"/> that contains requested navigation direction</param>
        /// <returns>Did handle tab</returns>
        protected override bool TabIntoCore(System.Windows.Input.TraversalRequest request)
        {
            if (_xamlSource.HasFocus && !_onTakeFocusRequested)
            {
                return(false); // If we have focus already, then we dont need to NavigateFocus
            }

            // Bug 17544829: Focus is wrong if the previous element is in a different FocusScope than the WindowsXamlHost element.
            var focusedElement = System.Windows.Input.FocusManager.GetFocusedElement(
                System.Windows.Input.FocusManager.GetFocusScope(this)) as FrameworkElement;

            var origin = BoundsRelativeTo(focusedElement, this);
            var reason = MapDirectionToReason[request.FocusNavigationDirection];

            if (_lastFocusRequest == Guid.Empty)
            {
                _lastFocusRequest = Guid.NewGuid();
            }

            var sourceFocusNavigationRequest = new WUX.Hosting.XamlSourceFocusNavigationRequest(reason, origin, _lastFocusRequest);

            try
            {
                var result = _xamlSource.NavigateFocus(sourceFocusNavigationRequest);

                // Returning true indicates that focus moved.  This will cause the HwndHost to
                // move focus to the source’s hwnd (call SetFocus Win32 API)
                return(result.WasFocusMoved);
            }
            finally
            {
                _lastFocusRequest = Guid.Empty;
            }
        }
Esempio n. 3
0
        private static void HandlePreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                System.Windows.Input.FocusNavigationDirection focusDirection = System.Windows.Input.FocusNavigationDirection.Next;
                System.Windows.Input.TraversalRequest request = new System.Windows.Input.TraversalRequest(focusDirection);
                UIElement elementWithFocus = sender as UIElement;

                if (elementWithFocus != null)
                    elementWithFocus.MoveFocus(request);
                e.Handled = true;
            }
        }
Esempio n. 4
0
        private static void HandlePreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                System.Windows.Input.FocusNavigationDirection focusDirection = System.Windows.Input.FocusNavigationDirection.Next;
                System.Windows.Input.TraversalRequest         request        = new System.Windows.Input.TraversalRequest(focusDirection);
                UIElement elementWithFocus = sender as UIElement;

                if (elementWithFocus != null)
                {
                    elementWithFocus.MoveFocus(request);
                }
                e.Handled = true;
            }
        }
Esempio n. 5
0
 public sealed override bool MoveFocus(System.Windows.Input.TraversalRequest request)
 {
     return(default(bool));
 }
 protected virtual new bool TabIntoCore(System.Windows.Input.TraversalRequest request)
 {
     return(default(bool));
 }
 bool System.Windows.Interop.IKeyboardInputSink.TabInto(System.Windows.Input.TraversalRequest request)
 {
     return(default(bool));
 }
Esempio n. 8
0
 public virtual new bool MoveFocus(System.Windows.Input.TraversalRequest request)
 {
     return(default(bool));
 }
 public virtual bool TabInto(System.Windows.Input.TraversalRequest request)
 {
     throw null;
 }
Esempio n. 10
0
 public bool MoveFocus(System.Windows.Input.TraversalRequest request)
 {
     return(inter.MoveFocus(request));
 }