/// <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;
         }
     }
 }
Example #2
0
 /// <summary>
 /// Responds to DesktopWindowsXamlSource TakeFocusRequested event
 /// </summary>
 /// <param name="sender">DesktopWindowsXamlSource</param>
 /// <param name="args">DesktopWindowXamlSourceTakeFocusRequestedEventArgs</param>
 private void OnTakeFocusRequested(Windows.UI.Xaml.Hosting.DesktopWindowXamlSource sender, Windows.UI.Xaml.Hosting.DesktopWindowXamlSourceTakeFocusRequestedEventArgs args)
 {
     if (_lastFocusRequest == args.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 correlationId
         var newRequest = new Windows.UI.Xaml.Hosting.XamlSourceFocusNavigationRequest(
             Windows.UI.Xaml.Hosting.XamlSourceFocusNavigationReason.Restore);
         _xamlSource.NavigateFocus(newRequest);
         _lastFocusRequest = newRequest.CorrelationId;
     }
     else
     {
         // Focus was not initiated by WindowsXamlHost. Continue processing the Focus request.
         var reason = args.Request.Reason;
         if (reason == Windows.UI.Xaml.Hosting.XamlSourceFocusNavigationReason.First || reason == Windows.UI.Xaml.Hosting.XamlSourceFocusNavigationReason.Last)
         {
             var forward = reason == Windows.UI.Xaml.Hosting.XamlSourceFocusNavigationReason.First;
             _forceFocusNavigation = true;
             try
             {
                 Parent.SelectNextControl(this, forward, tabStopOnly: true, nested: false, wrap: true);
             }
             finally
             {
                 _forceFocusNavigation = false;
             }
         }
     }
 }
        /// <summary>
        /// Responds to DesktopWindowsXamlSource TakeFocusRequested event
        /// </summary>
        /// <param name="sender">DesktopWindowsXamlSource</param>
        /// <param name="args">DesktopWindowXamlSourceTakeFocusRequestedEventArgs</param>
        private void OnTakeFocusRequested(Windows.UI.Xaml.Hosting.DesktopWindowXamlSource sender, Windows.UI.Xaml.Hosting.DesktopWindowXamlSourceTakeFocusRequestedEventArgs args)
        {
            var reason = args.Request.Reason;

            if (reason == Windows.UI.Xaml.Hosting.XamlSourceFocusNavigationReason.First || reason == Windows.UI.Xaml.Hosting.XamlSourceFocusNavigationReason.Last)
            {
                var forward = reason == Windows.UI.Xaml.Hosting.XamlSourceFocusNavigationReason.First;
                Parent.SelectNextControl(this, forward, tabStopOnly: true, nested: false, wrap: true);
            }
        }