Popup windows doesn't move up when Surface key

2019-02-15 10:31发布

问题:

I have a windows store application that requires the users to enter data via numerous textboxes.

When a textbox near the bottom of the screen has focus the on screen keyboard appears and moves the content of the page up. This is great and what I want.

My problem occurs when I have a popup window. When my popup window appears it is practically full screen. The popup window's child is a user control which again has lots of textboxes on it. When one of the textboxes near the bottom of the page is selected, the keyboard appears but the screen doesn't move up so the keyboard is appearing over the selected textbox.

This is the code I use to display my popup:

if (myPopup == null)
{
    myPopup = new Popup();

    myPopup.Child = new PopupFrom();

    // open the Popup                
    myPopup.IsOpen = true;
}

I also manually size the popup when the layout is updated

private void popup_LayoutUpdated(object sender, object e)
{
    if (Windows.UI.ViewManagement.ApplicationView.Value == Windows.UI.ViewManagement.ApplicationViewState.FullScreenLandscape)
    {
        popup.Width = 1280;
        popup.Height = 680;
    }
    else
    {
        popup.Width = 680;
        popup.Height = 1280;
    }
}

So my question is how can I move the popup window up when the keyboard is shown and overlapping one of the textboxes near the bottom of the popup?

Thanks in advance.

I'm using C# & XAML to write this windows 8 store app.

回答1:

In my app, I listen to the InputPane show/ hide events. These events tell you when the keyboard or other input device is shown/ hidden:

var pane = InputPane.GetForCurrentView();
pane.Showing += pane_Showing;
pane.Hiding += pane_Hiding;

In your event handlers, you can use the OccludedRect property to determine how big the input area (e.g. keyboard) is. Then you can shift your popup so that it does not cover this rectangle.



回答2:

You need to listen to gotFocus event for overlapped textboxes in order to modify popup's child dimensions. Also, I recomend to use a ScrollViewer as child for popup, to allow scrolling to above content. Something like : emailBox.GotFocus += (s, o) => AdjustPopup(); Good Luck!