locked
Losing focus of SwapChainPanel on mouse-button click, which loses ability to receive keyboard input

    Question

  • Hi,

    I'm working on getting some apps to render content to a SwapChainPanel, and to receive keyboard input.  To do this, I've added a very small Button as a child of the SwapChainPanel, as described in the MSDN Forum post at https://social.msdn.microsoft.com/Forums/windowsapps/en-US/54e4820d-d782-45d9-a2b1-4e3a13340788/set-focus-on-swapchainpanel-control?forum=winappswithcsharp .  This works okay, and I'm able to receive keyboard events.  If I then click anywhere on the screen, keyboard input stops working!  After a bit of research, I found that focus of my small button is lost, and is transferred to an unnamed element of class-type, "Windows.UI.Xaml.Controls.ScrollViewer" (when the screen is clicked).  My page's XAML file does not contain any scroll-viewer, just a Page, a SwapChainPanel, and a Button.  The SwapChainPanel is setup to occupy the entire screen.

    Any thoughts on what might be happening here, and how to make sure the SwapChainPanel retains its focus?

    To note, if I change the SwapChainPanel to a Grid, set it's Background property to "{ThemeResource ApplicationPageBackgroundThemeBrush}", listen for its OnPointerPressed event, and when received, set it's 'Handled' property to True, the control's focus is never lost.  I'm not sure why this works, and it doesn't work if I change it back to a SwapChainPanel.

    Cheers,

    -- David Ludwig

    Tuesday, March 10, 2015 8:27 PM

Answers

  • Ok, I figured it out...

    A SwapChainPanel must have a swap-chain set to it -before- it can stay focused.  I.e. ISwapChainPanelNative::SetSwapChain must be called with a valid swap chain before the control retains focus.  Content doesn't necessarily need to be drawn to the swap chain, it just needs to get set up.

    I had been writing a simplified user-input test, one that hadn't yet gone through the process of initializing the panel's swap-chain.  Once I made one and set it, this problem went away.


    -- David L.

    • Marked as answer by DavidLudwig Thursday, March 12, 2015 1:49 PM
    Thursday, March 12, 2015 1:49 PM

All replies

  • One extra note: for the apps I'm currently working on, which are ports of other apps, I'm trying to keep everything on the XAML UI thread, and as such, am trying not to collect input through a CoreIndependentInputSource.

    Cheers,

    -- David L.

    Tuesday, March 10, 2015 10:14 PM
  • Ok, I figured it out...

    A SwapChainPanel must have a swap-chain set to it -before- it can stay focused.  I.e. ISwapChainPanelNative::SetSwapChain must be called with a valid swap chain before the control retains focus.  Content doesn't necessarily need to be drawn to the swap chain, it just needs to get set up.

    I had been writing a simplified user-input test, one that hadn't yet gone through the process of initializing the panel's swap-chain.  Once I made one and set it, this problem went away.


    -- David L.

    • Marked as answer by DavidLudwig Thursday, March 12, 2015 1:49 PM
    Thursday, March 12, 2015 1:49 PM
  • Hi David,

    Wow, nice to see the solution. Thanks for sharing with us.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 13, 2015 2:37 AM
    Moderator