且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

显示键盘时,滚动受到限制

更新时间:2023-11-26 14:32:28

这是一个已知问题,由 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.