显示键盘时,滚动受到限制 [英] when keyboard is show, scrolling is limited

查看:52
本文介绍了显示键盘时,滚动受到限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 手机中滚动时遇到问题.我在页面上有很多元素,所以为了增加滚动能力,我把它放在 ScrollViewer 上.然而,当我聚焦在某个文本块上并且键盘出现时,滚动条在工作,但它会切割页面的顶部和底部,因此用户无法访问它.您的应用是否遇到过类似问题并知道如何解决?

I have a problem with scrolling in windows phone. I have a lot of elements on page so to add ability to scroll I put this on ScrollViewer. Hovewer, when I foucesd on some text block and the keyborad shows up, the scroll in working but it cuts the top and bottom of the page so it's can't be reach by user. Have you had similar problem with your apps and know how to fix this ?

我将非常感谢您的帮助

当我把我的问题截图时链接到图像

图片包含四张截图:

1) 页面顶部

2) 页面底部

3) 关注第一个文本框

3) Focus on the first textbox

4) 当焦点设置在第一个 TextBox 时可以到达的页面区域

4) The area on the page which can be reached when focus is set to the first TextBox

最后一张图片展示了当焦点设置到第一个文本框时可以调整的区域.如您所见,当显示键盘时,我无法进入 Field 7 下方的文本框.

The last one picture present the are which can be rached when focus is set to the first textbox. As you can see I can't get to the textboxes below Field 7 when keybord is shown.

我需要的是在显示键盘时能够滚动并到达所有元素.

What I need is the ability to scroll and to reach all elements when the keybord is shown.

你知道如何解决我的问题吗

Do you know how to resolve my poblem

这是我的 xaml 代码:

It's my xaml code:

<phone:PhoneApplicationPage
    x:Class="PhoneApp6.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <ScrollViewer Grid.Row="1" Height="600" Margin="12 0">
            <StackPanel>
                <StackPanel>
                    <TextBlock  Text="Name 1" />
                    <TextBox  />
                </StackPanel>

                <StackPanel>
                    <TextBlock  Text="Name 2" />
                    <TextBox  />
                </StackPanel>

                <StackPanel>
                    <TextBlock  Text="Name 3" />
                    <TextBox  />
                </StackPanel>

                <StackPanel>
                    <TextBlock  Text="Name 4" />
                    <TextBox  />
                </StackPanel>

                <StackPanel>
                    <TextBlock  Text="Name 5" />
                    <TextBox  />
                </StackPanel>

                <StackPanel>
                    <TextBlock  Text="Name 6" />
                    <TextBox  />
                </StackPanel>

                <StackPanel>
                    <TextBlock  Text="Name 7" />
                    <TextBox  />
                </StackPanel>

                <StackPanel>
                    <TextBlock  Text="Name 8" />
                    <TextBox  />
                </StackPanel>

                <StackPanel>
                    <TextBlock  Text="Name 9" />
                    <TextBox  />
                </StackPanel>

                <StackPanel>
                    <TextBlock  Text="Name 10" />
                    <TextBox  />
                </StackPanel>

                <Button>Submit</Button>
            </StackPanel>
        </ScrollViewer>
    </Grid>

</phone:PhoneApplicationPage>

推荐答案

这是一个已知问题,由 SIP 更改屏幕的可视区域引起.David Gorden 提到的链接确实有帮助,但您实际上需要更改滚动查看器的高度才能获得完美的效果.为了使事情更复杂一点,WP 不会在 SIP 可见时触发事件!因此,您需要挂钩 GotFocus/LostFocus 事件.

This is a known issue and is caused by the SIP changing the viewable area of the screen. The link David Gorden mentioned does help, but you actually need to change the height of the scrollviewer to achieve perfect results. To make things a little more complex WP does not trigger an event for when the SIP is visible! So you need to hook into the GotFocus/LostFocus events.

编辑您的滚动查看器,使其看起来像这样:

Edit your scrollviewer so it looks something like this:

<ScrollViewer x:Name="_scrollViewer"
                  VerticalAlignment="Top"
                  GotFocus="UIElement_OnGotFocus"
                  LostFocus="UIElement_OnLostFocus" 
                  ... bla bla

现在在代码隐藏中添加以下内容:

Now add the following in the codebehind:

private bool _isHdDevice;
    private int _sipHeight;
    private double _origHeight;

    // Constructor
    public MainPage()
    {
        InitializeComponent();

        // todo - cater for landscape mode or sip scopenames that require extra space (predictive text and cut&paste icon)
        var deviceWidth = this.ActualWidth;
        _isHdDevice = (deviceWidth > 500);
        _sipHeight = _isHdDevice ? 540 : 375;
        _origHeight = _scrollViewer.Height;
    }

    private void UIElement_OnGotFocus(object sender, RoutedEventArgs e)
    {
        double height = this.ActualHeight - _sipHeight - TitlePanel.ActualHeight;
        _scrollViewer.Height = height;
        // the following lines are crucial otherwise a black band could appear above the SIP
        App.Current.RootVisual.RenderTransform = new CompositeTransform();
        this.UpdateLayout();
    }

    private void UIElement_OnLostFocus(object sender, RoutedEventArgs e)
    {
        _scrollViewer.Height = _origHeight;
    }

这基本上是在 sip(键盘)可见时调整滚动区域的大小.您将需要添加更多代码来满足诸如屏幕旋转、与文本框关联的范围名称以及在视图中剪切和粘贴图标之类的内容.但这会让你继续前进并完成困难的部分.

This is basically resizing the scroll area when the sip (keyboard) is in view. You will need to add more code to cater for things like screen rotation, scopename associated to the textbox, and cut&paste icon if in view. But this will get you going and does the difficult bit.

如果有助于解决问题,请将其标记为已回答.

Please mark as answered if it helped fix the issue.

这篇关于显示键盘时,滚动受到限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆