查看键盘打开时的所有元素- Windows 10 Mobile - XAML - c#

本文关键字:Windows 元素 Mobile XAML 键盘 | 更新日期: 2023-09-27 18:18:38

我正在开发一个页面,我有一些疑问。我的项目是Windows 10 Mobile。在我正在开发的页面上,当一个文本框有焦点时,手机键盘打开,我得到了其余的隐藏元素,并且不允许我滚动页面以查看所有元素。

我走到做在互联网上,但我看到的解决方案取决于确保更大的尺寸,我的StackPanel比我的ScrolViewer,但我不需要它为好。例如ScrollViewer宽度= 500…

当键盘上希望能够看到所有元素时,进行滚动。

跟随我的代码:

    <ScrollViewer x:Name="ScrollViewerTest VerticalAlignment="Top">
            <StackPanel Orientation="Vertical" Margin="10,10,10,10">
                    <TextBox x:Name="txtUserNameMobile" IsSpellCheckEnabled="False" 
                             Background="Black" Foreground="White"
                             PlaceholderText="Insert your text"
                             />
                    <Button x:Name="btnHere" 
                            Content="btnHere" 
                            Height="48"
                            Width="150">
                    <Button x:Name="btnHere2" 
                            Content="btnHere2" 
                            Height="48"
                            Width="150">
                    <Button x:Name="btnHere3" 
                            Content="btnHere3" 
                            Height="48"
                            Width="150">
                    <Button x:Name="btnHere4" 
                            Content="btnHere4" 
                            Height="48"
                            Width="150">
                     <Button x:Name="btnHere5" 
                            Content="btnHere5" 
                            Height="48"
                            Width="150">
        </StackPanel>
</ScrollViewer>

有人能帮帮我吗?

查看键盘打开时的所有元素- Windows 10 Mobile - XAML - c#

可以覆盖TextBox焦点上的页面默认滚动行为,并且可以添加自定义逻辑以在显示键盘时显示焦点TextBox。使用该方法可以使ScrollViewer在键盘打开时滚动。

InputPane.GetForCurrentView().Showing += InputPane_Showing;
private void InputPane_Showing(InputPane sender, InputPaneVisibilityEventArgs args)
        {
             args.EnsuredFocusedElementInView = true; //This will prevent the auto scroll of the page.
        }

args.OccludedRect将给出与键盘相关的属性,如高度,顶部位置等。如果TextBox隐藏在键盘后面,可以使用这些值将其移动到所需的位置。