I have a page with a vertical set of textboxes. If one of them is focused, all of them should be visible, even if the onscreen keyboard is displayed. There are just enough of them that all of them fit in the available space above the keyboard. When the bottom textbox is focused, the page gets automatically scrolled up so that all of them are visible, but if the top textbox is focused, the onscreen keyboard covers the bottom one.
This is a simplified example of my page:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<ItemsControl ItemsSource="{Binding List}" Margin="120 140 0 0">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0 10 0 0">
<TextBox Text="{Binding Text, Mode=TwoWay}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
DataContext
contains a list of 10 items:
public class Item
{
public string Text { get; set; }
}
public class ViewModel
{
public List<Item> List { get; set; }
}
public MainPage()
{
this.InitializeComponent();
DataContext = new ViewModel
{
List = Enumerable.Range(0, 10).Select(i => new Item { Text = i.ToString() }).ToList()
};
}
I've already tried a couple of approaches, all without success:
- In
TextBox.GotFocus
event programmatically changed focus to the bottom textbox and back. - In
TextBox.GotFocus
event andInputPane.Showing
event tried setting the vertical offset of aScrollViewer
: (a) the one I included in the page around theGrid
(b) the one in the visual tree above thePage
that Windows uses to automatically bring the focused control in view. In both cases theScrollViewer
doesn't react toScrollToVerticalOffset
calls.
I've also looked at the sample suggested in this question but it reacts to onscreen keyboard differently, not by scrolling the page.