3

I have a Windows 8.1 C# app that shows a page with a pretty big textbox (covering almost all of the page; its a writing app).

When the on screen keyboard shows up, it overlays half of the textbox. I would like to resize the textbox (or even the whole page) so it isnt covered by the keyboard.

I am now thrying to achieve this using the static InputPane and subscribing to its showing and hiding events. I then try to change the margins of my textbox using the occuled rectangle provided in the eventargs. This works, but since my page is still the height of the screen it scrolls it halfway to the bottom.

public MainPage()
{
    var inputPane = InputPane.GetForCurrentView();
    inputPane.Showing += this.InputPaneShowing;
    inputPane.Hiding += this.InputPaneHiding;
}

void InputPaneHiding(InputPane sender, InputPaneVisibilityEventArgs args)
{
    this.EditBox.Margin = new Thickness();
}

private void InputPaneShowing(InputPane sender, InputPaneVisibilityEventArgs args)
{
    this.EditBox.Margin = new Thickness(0, 0, 0, args.OccludedRect.Height);
}

While trying this out I'm getting the feeling this isnt the ideal solution, but I havent got a better idea. Ideally I'd think it would be something like the vertical split when you have to apps opened, but then horizontally with the keyboard at the bottom and the app only the size available above the keyboard.

Any idea if this is possible?

Raf
  • 663
  • 1
  • 8
  • 21
  • 1
    Have you tried setting the `Margin` of the Page or setting directly its Height? – Rafael Nov 25 '13 at 20:18
  • Yes @Rafael, I tried the 'Margin' and it caused a bit of strange behaviour where it would still scroll my page up like it was its original size which caused a black space to apear where my (white) page stopped. (dont know if thats clear, difficult to explain in writing :) ). Height I'm trying now! – Raf Nov 25 '13 at 20:20
  • Hmm, when setting the height of the Page, it doesn't do anything. I'm also seeing that Height is NaN before I am setting it with my calculated value (after which it still stays NaN by the way). Is this normal? – Raf Nov 25 '13 at 20:23
  • Mmm... Strange, I can't test this given that I don't have touch enabled computer at hand :-S. – Rafael Nov 25 '13 at 20:39
  • Hi @Rafael, I'm also trying this in the simulator. I have got a touch device here also, but it's giving the same results... – Raf Nov 25 '13 at 20:44

1 Answers1

6

Since you are handling the interface occlusion yourself you should set the property EnsuredFocusedElementInView from InputPane.Showing eventargs to true. It would prevent interface from automatically scrolling.

 private void InputPaneShowing(InputPane sender, InputPaneVisibilityEventArgs args)
 {
    args.EnsuredFocusedElementInView = true;
    this.EditBox.Margin = new Thickness(0, 0, 0, args.OccludedRect.Height);
 };
Cyprien Autexier
  • 1,948
  • 16
  • 20
  • Thank you, @Cyprien-Autexier, I'll try this when I'm back at home this evening! – Raf Nov 26 '13 at 14:05
  • Stunning @Cyprien, works like a charm! I'm setting the margin of my page(instead of the EditBox) now, which cause my whole app to take up the remaining space above the keyboard and it looks perfect! – Raf Nov 28 '13 at 20:35