Windows phone 8.1 InputPane无法正常工作
我目前正在开发一个通用应用程序,但有一个问题。我有一个框,框中有用户电话号码的文本框。 因此,我想更改LayoutRoot(网格)的高度,使其适合自由空间。Windows phone 8.1 InputPane无法正常工作,windows-phone-8.1,windows-phone,win-universal-app,windows-10-universal,windows-10-mobile,Windows Phone 8.1,Windows Phone,Win Universal App,Windows 10 Universal,Windows 10 Mobile,我目前正在开发一个通用应用程序,但有一个问题。我有一个框,框中有用户电话号码的文本框。 因此,我想更改LayoutRoot(网格)的高度,使其适合自由空间。 我正在使用InputPane.GetForCurrentView()。显示和InputPane.GetForCurrentView()。为此目的隐藏。 这是我的密码 public UserRegistrationAuthorization_PhoneNumber() { this.InitializeCompone
我正在使用
InputPane.GetForCurrentView()。显示和InputPane.GetForCurrentView()。为此目的隐藏。
这是我的密码
public UserRegistrationAuthorization_PhoneNumber()
{
this.InitializeComponent();
LayoutRootInitialHeight = LayoutRoot.ActualHeight;
InputPane.GetForCurrentView().Showing += UserRegistrationAuthorization_PhoneNumber_Showing;
InputPane.GetForCurrentView().Hiding += UserRegistrationAuthorization_PhoneNumber_Hiding;
}
private void UserRegistrationAuthorization_PhoneNumber_Showing(InputPane sender, InputPaneVisibilityEventArgs args)
{
LayoutRoot.Height = LayoutRoot.ActualHeight - args.OccludedRect.Height;
LayoutRoot.VerticalAlignment = VerticalAlignment.Top;
args.EnsuredFocusedElementInView = true;
}
private void UserRegistrationAuthorization_PhoneNumber_Hiding(InputPane sender, InputPaneVisibilityEventArgs args)
{
// TODO: Get rid of that shit
LayoutRoot.Height = LayoutRootInitialHeight;
args.EnsuredFocusedElementInView = false;
}
当我在文本框外单击时,键盘会隐藏并在屏幕上留下一个黑洞
但是,最有趣的是,当我按下Lumia上的物理后退按钮时,键盘正常隐藏,LayoutRoot获得帧的初始高度
是虫子还是我做错了什么 之所以会发生这种情况,是因为在构造函数中保存LayoutRootTinitialHeight时,LayoutRoot实际上没有加载,它的实际高度==0。然后将LayoutRoot.Height设置为0,使其不可见。因此,您可能应该将LayoutRootTinitialHeight保存在LayoutRoot的已加载事件处理程序中
我还建议你根本不要改变LayoutRoot的高度。它会导致整个视觉树从头开始渲染,这通常是不好的做法。相反,请修改所有必要图元的RenderTransform,以便将它们移动到适当的位置。RenderTransform是处理屏幕上的运动和动画的正确方法,您可以通过“下一步”按钮向上移动(与键盘相同)来获得一些不错的视觉效果
您的代码大致如下所示:
<Button Content="Next" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center">
<Button.RenderTransform>
<CompositeTransform x:Name="NextButtonTransform" TranslateY="0"/>
</Button.RenderTransform>
</Button>
更复杂的方法是运行一些故事板,使你们的下一个按钮以和键盘相同的速度上下移动,总是出现在上面。尽管如此,由于InputPane.GetForCurrentView().Showing在键盘完全显示后被激发,您应该将所有动画连接到TextBox.GotFocus和TextBox.LostFocus事件。在手机上,当文本框有焦点时,键盘总是显示出来,所以它会很好地工作。感谢您提供的详细答案!
private void UserRegistrationAuthorization_PhoneNumber_Showing(InputPane sender, InputPaneVisibilityEventArgs args)
{
NextButtonTransform.TranslateY = -300;
EnsuredFocusedElementInView = true;
}
private void UserRegistrationAuthorization_PhoneNumber_Hiding(InputPane sender, InputPaneVisibilityEventArgs args)
{
NextButtonTransform.TranslateY = 0;
args.EnsuredFocusedElementInView = false;
}