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;
}

Leave a Comment

Copyright © 2019 Soulmedic Theme All Rights Reserved | Design Themes

Atomic Flavor