uwpresourcedictionarysoft-keyboardflipviewdatatemplateselector

UWP: Soft Keyboard doesn't scroll focused TextBox (nested in a FlipView) into View


I thought it's pretty standard to get the

'scroll the focused TextBox into view when soft keyboard appears'

but the more time I spend trying to solve this problem, the more it feels like dividing by zero.

I wrote an app with a flipview, filled with programmatically created pages.

My app goes ViewModelFirst so the Xaml-Views are loaded from a ResourceDictionary via DataTemplateSelector.

A TextBox at the bottom of the MainPage (a xaml-page - not from ResourceDictionary) works.

As soon as the page comes from the DataTemplateSelector (and therefore necessarily from the ResourceDictionary)it does not behave as expected.

BTW: I decided to go the way with the ResourceDictionary because it seemed to me to be impossible to get a DataTemplate from a xaml-page. If someone knows a way for doing this, please tell me :)

So here's my example project: https://drive.google.com/file/d/0BzDVtvE9NKaMd2dBMWMzTWJtN1E/view?usp=sharing

Thank you all in advance

Best regards Alex


Solution

  • I solved this by changing the ItemsPanel of the FlipView to a horizontal scrolling StackPanel. By default a VirtualizingStackPanel is in use.

    My method looks like this:

    private ItemsPanelTemplate GetItemsPanelTemplate() {
                string xaml = "<ItemsPanelTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'><StackPanel Orientation='Horizontal' AreScrollSnapPointsRegular='True' /></ItemsPanelTemplate>";
                return XamlReader.Load(xaml) as ItemsPanelTemplate;
            }
    

    And I call this method like this:

    Flip.ItemsPanel = GetItemsPanelTemplate();
    

    And here I have to thank feO2x (https://stackoverflow.com/users/1560623/feo2x) for his entry in his blog (http://www.feo2x.com/posts/2015-12-06-flipview-and-problems-with-input-controls-part-1/)

    But be aware: according to feO2x's blogpost the VirtualizingStackPanel uses a kind of lazy loading but the now used (standard) StackPanel don't. So it might be slower.

    I hope, this may help someone.