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

Windows phone 7 显示键盘时,滚动受到限制,windows-phone-7,windows-phone-8,scroll,windows-phone,scrollviewer,Windows Phone 7,Windows Phone 8,Scroll,Windows Phone,Scrollviewer,我在windows phone中滚动时遇到问题。我在页面上有很多元素,所以为了增加滚动的能力,我把这个放到了ScrollViewer上。Hovewer,当我在某个文本块上搜索时,键盘显示出来,滚动条开始工作,但它会剪切页面的顶部和底部,因此用户无法触及。您的应用程序是否存在类似问题,并且知道如何解决此问题 我将非常感谢你的帮助 该图片包含四个屏幕截图: 1) 页首 2) 这一页的底部 3) 关注第一个文本框 4) 当焦点设置为第一个文本框时可以到达的页面区域 当焦点设置为第一个文本框时,最后

我在windows phone中滚动时遇到问题。我在页面上有很多元素,所以为了增加滚动的能力,我把这个放到了ScrollViewer上。Hovewer,当我在某个文本块上搜索时,键盘显示出来,滚动条开始工作,但它会剪切页面的顶部和底部,因此用户无法触及。您的应用程序是否存在类似问题,并且知道如何解决此问题

我将非常感谢你的帮助


该图片包含四个屏幕截图:

1) 页首

2) 这一页的底部

3) 关注第一个文本框

4) 当焦点设置为第一个文本框时可以到达的页面区域

当焦点设置为第一个文本框时,最后一张图片可以显示。如您所见,当显示keybord时,我无法进入字段7下方的文本框

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

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


这是我的xaml代码:

<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提到的链接确实有帮助,但实际上需要更改scrollviewer的高度才能获得完美的结果。让事情变得更复杂一点,当SIP可见时,WP不会触发事件!因此,您需要连接到GotFocus/LostFocus事件

编辑您的scrollviewer,使其看起来像这样:

<ScrollViewer x:Name="_scrollViewer"
                  VerticalAlignment="Top"
                  GotFocus="UIElement_OnGotFocus"
                  LostFocus="UIElement_OnLostFocus" 
                  ... bla bla
这基本上是在查看sip(键盘)时调整滚动区域的大小。您需要添加更多的代码,以适应屏幕旋转、与文本框关联的scopename以及视图中的剪切粘贴图标等情况。但这会让你继续前进,并完成困难的部分


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

如果我理解正确,我自己的应用程序也有类似问题,无法在键盘可见时向下滚动至最低文本框。由于我不是那么聪明,我用以下方法解决了这个问题:一个间隔键,当键盘打开时出现,当键盘不打开时消失

在我的scrollviewer中输入的文本框项目都在wrappanels中,以保持整洁。在最后一个包裹面板下面,我添加了另一个空包裹面板,名为“间隔”,高度为120。默认情况下,它设置为visibility.collapped

作为包装面板中每个文本框的gotfocus事件处理程序的一部分,我将间隔设置为visible。这允许在键盘打开时滚动到我的滚动查看器中的最后一个包装盒/文本框

作为每个文本框的lostfocus事件处理程序的一部分,间隔符的可见性设置为“折叠”。这样,当没有键盘时,scrollviewer底部就不会有一个大的、时髦的、空的空间


这可能不是很优雅,但它很简单,对我来说效果很好。我还没有遇到任何问题,但这并不意味着我没有遗漏任何东西。

你能分享一些屏幕截图来更好地解释这个问题吗?我相信这个答案可能会有所帮助。谢谢,我会等的。我明白了,我觉得行为会很棒,这样我就可以重用这个类了。但我还有一个问题,在哪里可以找到定制类型SIP的官方尺寸(高度)?这是一个好问题。老实说,我自己还没有找到确切的尺码。我使用的尺寸适用于emulator、HTC Mozart和诺基亚820设备。
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;
    }