Windows 10 Mobile height of soft keyboard

流过昼夜 提交于 2021-02-07 09:23:36

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/36091928/windows-10-mobile-height-of-soft-keyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!