Konstantin Chsherbakov
Konstantin Chsherbakov

Reputation: 652

Windows 10 Mobile height of soft keyboard

Does anybody know how to move content of the page (maybe set relative margins or something like that) when soft keyboard is shown.

Here is the example page from my application.

1

So I want when the user starts typing a phone number in the text box the bottom button will be shown above the soft keyboard. As a result I want something like that:

1

P.S: Sorry about Russian language on the screens.

Upvotes: 2

Views: 545

Answers (1)

Romasz
Romasz

Reputation: 29792

It's kind of tricky, but as I've tried should work. I've used InputPane's showing and hiding events to change the translate transform of the button. In page's constructor I've added such code:

Windows.UI.ViewManagement.InputPane.GetForCurrentView().Showing += (s, args) =>
{
    GeneralTransform gt = loginButton.TransformToVisual(this);
    Point buttonPoint = gt.TransformPoint(new Point(0, loginButton.RenderSize.Height - 1));
    var trans = new TranslateTransform { Y = -(buttonPoint.Y - args.OccludedRect.Top) };
    loginButton.RenderTransform = trans;
    args.EnsuredFocusedElementInView = true;
};

Windows.UI.ViewManagement.InputPane.GetForCurrentView().Hiding += (s, args) =>
{
    var trans = new TranslateTransform { Y = 0 };
    loginButton.RenderTransform = trans;
    args.EnsuredFocusedElementInView = false;
};

You only have to remember that InputPane is for the whole app - once you leave the page, you will probably have to unsubscribe from those events, otherwise you will likely get exceptions.

Upvotes: 3

Related Questions