WinRT: Programmatically scroll controls into view when virtual keyboard opens

Use this code:

 private void TextBoxUserGotFocus(object sender, RoutedEventArgs e)
        {
           //Subir el teclado
            var inputPane = InputPane.GetForCurrentView();
            inputPane.Showing += InputPane_Showing;
        }

private async void InputPane_Showing(InputPane sender, InputPaneVisibilityEventArgs args)
{
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            var parentScrollViewer = FindParent(this.pageRoot);
            parentScrollViewer.VerticalScrollMode = ScrollMode.Enabled;
            parentScrollViewer.ScrollToVerticalOffset(65);
            parentScrollViewer.UpdateLayout();
        });
}

public static T FindParent(FrameworkElement reference)
    where T : FrameworkElement
{
    FrameworkElement parent = reference;
    while (parent != null)
    {
        parent = parent.Parent as FrameworkElement;

        var rc = parent as T;
        if (rc != null)
        {
            return rc;
        }
    }

    return null;
}
WinRT: Programmatically scroll controls into view when virtual keyboard opens WinRT: Programmatically scroll controls into view when virtual keyboard opens Reviewed by Unknown on 18:10 Rating: 5

No hay comentarios:

Con la tecnología de Blogger.