Raf*_*Raf 3 c# keyboard textbox windows-runtime
我有一个Windows 8.1 C#应用程序,显示一个带有相当大的文本框的页面(几乎涵盖了所有页面;它是一个写作应用程序).
当屏幕键盘出现时,它覆盖了文本框的一半.我想调整文本框(甚至整个页面)的大小,以便它不被键盘覆盖.
我现在正在使用静态InputPane并订阅其显示和隐藏事件来实现此目的.然后我尝试使用eventargs中提供的带有方框的矩形来更改文本框的边距.这是有效的,但由于我的页面仍然是屏幕的高度,因此它将其向下滚动到底部.
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);
}
Run Code Online (Sandbox Code Playgroud)
在尝试这一点时,我感觉这不是理想的解决方案,但我没有更好的主意.理想情况下,我认为当你需要打开应用程序时,它会像垂直分割一样,但是底部的键盘是水平的,而应用程序只是键盘上方的可用尺寸.
知道这是否可行?
由于您自己处理接口遮挡,因此应将InputPane.Showing eventargs中的属性EnsuredFocusedElementInView设置为true.它会阻止界面自动滚动.
private void InputPaneShowing(InputPane sender, InputPaneVisibilityEventArgs args)
{
args.EnsuredFocusedElementInView = true;
this.EditBox.Margin = new Thickness(0, 0, 0, args.OccludedRect.Height);
};
Run Code Online (Sandbox Code Playgroud)