【问题标题】:See all elements when Keyboard Open - Windows 10 Mobile - XAML - C#键盘打开时查看所有元素 - Windows 10 移动版 - XAML - C#
【发布时间】:2016-01-20 17:16:36
【问题描述】:

我正在开发一个页面,但我有一些疑问。 我的项目适用于 Windows 10 移动版。在我正在开发的页面上,当一个文本框有焦点时,手机键盘向上,我得到了其余的隐藏元素,并且不允许我滚动将 poara 页面查看所有元素。

Ja 在互联网上行走,但我看到解决方案取决于确保我的 StackPanel 的大小比我的 ScrolViewer 更大,但我也不需要它。 例如 ScrollViewer 宽度 = 500 ... StackPanel 宽度 = 700

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

按照我的代码:

    <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>

有人可以帮助我吗?

【问题讨论】:

    标签: c# xaml keyboard scrollview windows-10-mobile


    【解决方案1】:

    可以覆盖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 隐藏在键盘后面,这些值可用于将其移动到所需位置。

    【讨论】:

    • 嗨@Bells。没有解决我的问题,但我今天早上刚刚通过键盘大小修复,可以使我的滚动浏览器和我的网格有不同的大小,从键盘中减去可见的值。还是谢谢
    猜你喜欢
    • 1970-01-01
    • 2016-02-15
    • 2020-04-28
    • 1970-01-01
    • 1970-01-01
    • 2012-08-14
    • 2020-06-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多