键盘处于活动状态时,ScrollViewer不会向上滚动

时间:2013-02-05 12:23:53

标签: windows-phone-7

如何在Windows Phone中获取表单行为,例如设置>>移动网络>> EditAPN。在此页面中,它在scrollviewer中有许多文本框。当用户点击任何文本框并获得焦点时,页面向上滚动并且页眉保持不变并显示SIP键盘。当用户从此文本框中丢失焦点时,页面将进入正常状态,SIP键盘隐藏和标题保持不变。我想实现这种行为。我搜索了很多但没有得到任何解决方案。 很奇怪在WP7中看到scrollviewer行为。 任何帮助都将是伟大而可观的。 提前致谢。 注意:如果有任何棘手的解决方案,请提供示例代码。

这是我的示例代码。

<Grid x:Name="ContentPanel" Grid.Row="1" >
            <ScrollViewer x:Name="Scroller">
                <StackPanel Orientation="Vertical">

                    <TextBlock Text="Name"/>
                    <TextBox x:Name="txtName" />
                    <TextBlock Text="Email"/>
                    <TextBox x:Name="txtEmail"/>
                    <TextBlock Text="Phone"/>
                    <TextBox x:Name="txtPhone" />
                    <TextBlock Text="Adress"/>
                    <TextBox x:Name="txtAddress" />                 

                </StackPanel>
            </ScrollViewer>
        </Grid>

当我尝试向下滚动时,它不会完全向下移动并且似乎有弹性。

编辑: 这个例子,我已经看过,在我的案例中没用。我有4个文本框,我的重点是第一个文本框和键盘来隐藏最后一个文本框。如果用户想要转到上一个文本框并想要输入输入,则它不会完全滚动并且具有弹性。对于此用户必须按下屏幕的其他部分,然后他进入最后一个框。我在设置中的WP7应用程序中看到了 - &gt;移动网络 - &gt; EditAPN。有4-5个文本框,这些完美滚动。不知道MSFT使用哪种控件或解决方法。

1 个答案:

答案 0 :(得分:1)

也许我错了,但为什么不使用简单的网格和listpicker控件。您将需要Windows Phone Toolkit(Nuget Here)。

网格的第一行包含标题,不会更改。 第二行包含您想要的内容(scrollview,listpicker,...)

这是一个非常基本的例子:

<phone:PhoneApplicationPage 
    x:Class="PhoneApp3.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" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    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="PageTitle" Text="MY HEADER" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <Grid x:Name="ContentPanel" Grid.Row="1">
            <toolkit:ListPicker>
                <toolkit:ListPickerItem Content="aaa" />
                <toolkit:ListPickerItem Content="bbb" />
                <toolkit:ListPickerItem Content="ccc" />
            </toolkit:ListPicker>
        </Grid>
    </Grid>
</phone:PhoneApplicationPage>

修改:

呈现SIP键盘时,PhoneApplicationFrame.TranslateTransform.Y设置为特定值(横向为-259,纵向为-339)。要更新布局,我们只需将上边距设置为指定值(-s),然后Silverlight布局系统将解决问题。

example可能会对您有所帮助。

相关问题