C# 当关注用户控件内的文本框时检测虚拟键盘
我在winRT项目中有以下FlipViewC# 当关注用户控件内的文本框时检测虚拟键盘,c#,xaml,user-controls,windows-runtime,windows-store-apps,C#,Xaml,User Controls,Windows Runtime,Windows Store Apps,我在winRT项目中有以下FlipView <FlipView x:Name="Flip" GotFocus="FlipView_GotFocus" Grid.Row="1" ItemsSource="{Binding Controls, ElementName=pageRoot}" SelectedItem="{Binding SelectedControl, ElementName=pageRoot, Mode=TwoWay}"> <FlipView.Ite
<FlipView x:Name="Flip" GotFocus="FlipView_GotFocus" Grid.Row="1" ItemsSource="{Binding Controls, ElementName=pageRoot}" SelectedItem="{Binding SelectedControl, ElementName=pageRoot, Mode=TwoWay}">
<FlipView.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<ContentPresenter Content="{Binding}" />
</Grid>
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
现在我只需要学习如何向上拉视图。正如您所发现的,您可以使用InputPane的显示和隐藏事件来检测InputPane的可见性更改。InputPaneVisibilityEventArgs包括它将覆盖的OccludedRect,您可以将RenderTransform应用到页面以将其转换为其他方式
<Page.RenderTransform>
<CompositeTransform x:Name="pageTransform"/>
</Page.RenderTransform>
实际上,你需要做一些数学计算,以确保必要的控件在视图中。可以使用动画使移动更加平滑。如果你想变得更具创造性,你可以切换到一个新的视觉状态,它只有在一个更友好的布局中编辑所需的字段。在UserControl的情况下,您可能只想移动控件而不是页面
另外,在Windows 10桌面上对其进行测试,因为软键盘行为与窗口应用程序的交互方式略有不同。这篇文章有帮助
Windows.UI.ViewManagement.InputPane.GetForCurrentView().Showing
Windows.UI.ViewManagement.InputPane.GetForCurrentView().Hidding
<Page.RenderTransform>
<CompositeTransform x:Name="pageTransform"/>
</Page.RenderTransform>
void Page_Showing(InputPane sender, InputPaneVisibilityEventArgs args)
{
// We probably want something more sophisticated to make sure the
// focus control and any dependencies are in view
pageTransform.TranslateY -= args.OccludedRect.Height;
// Tell the InputPane we already handled things so it doesn't move the page again
args.EnsuredFocusedElementInView = true;
}
void Page_Hiding(InputPane sender, InputPaneVisibilityEventArgs args)
{
pageTransform.TranslateY = 0;
args.EnsuredFocusedElementInView = true;
}