1

Windows Phone 7アプリケーションに、多くのテキストボックスを含むページがいくつかあります。Windows Phone 7にはデフォルトの動作があり、テキストボックスにフォーカスを合わせると、SIPキーボードが表示されてページ全体が上にスライドし、フォーカスが失われると通常の状態に戻ります。私のアプリケーションではこれを制限したいと思います。私がグーグルで解決策を見つけたので、すべてのコントロールをそのテキストボックスの位置に設定されたスクロールビューアの垂直オフセットscrollviewerのフォーカスを取得して配置します。textbox

  1. 今、私はそのスクロールビューアーに垂直オフセットのコントロールの位置をどのように伝えることができるか混乱しています。

  2. そして、それを設定できるのであれば、テキストボックスとの2つのメソッドを呼び出す必要があるon GotFocusとしOn LostFocusます。相互作用の振る舞いとトリガーを介してこれを呼び出すことができる他のアプローチはありますか?

アップデート...

<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-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="480" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <ScrollViewer x:Name="sc">
                <StackPanel>
                    <Grid x:Name="Grid1" Grid.Row="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="80" />
                <RowDefinition Height="80" />
                <RowDefinition Height="80" />
                <RowDefinition Height="80" />
                <RowDefinition Height="80" />
                <RowDefinition Height="80" />
            </Grid.RowDefinitions>
                    <TextBox Width="460" AcceptsReturn="True" Grid.Row="0" x:Name="txtbox1"/>
                    <TextBox Width="460" AcceptsReturn="True" Grid.Row="1" x:Name="txtbox2"/>
                    <TextBox Width="460" AcceptsReturn="True" Grid.Row="2" x:Name="txtbox3"/>
                    <TextBox Width="460" AcceptsReturn="True" Grid.Row="3" x:Name="txtbox4"/>
                    <TextBox Width="460" AcceptsReturn="True" Grid.Row="4" x:Name="txtbox5"/>
                    <TextBox Width="460" AcceptsReturn="True" Grid.Row="5" x:Name="txtbox6" GotFocus="txtbox6_GotFocus"/>
            </Grid>
                </StackPanel>
            </ScrollViewer>
            <Grid x:Name="Grid2" Grid.Row="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="80" />
                </Grid.RowDefinitions>
                <Button x:Name="btnTest" Width="250" Content="Test" Grid.Row="0" />
            </Grid>
        </Grid>
    </Grid>

AND CS C#...。

void ScrollToFocused(ScrollViewer scrollviewer)
{
    FrameworkElement focusedElement = FocusManager.GetFocusedElement() as FrameworkElement;
    // verify focused control is a child of the ScrollViewer 
    if (scrollviewer != null && focusedElement != null && IsVisualChild(scrollviewer, focusedElement))
    {
        GeneralTransform focusedVisualTransform = focusedElement.TransformToVisual(scrollviewer);
        Rect rectangle = focusedVisualTransform.TransformBounds(new Rect(new Point(focusedElement.Margin.Left, focusedElement.Margin.Top), focusedElement.RenderSize));
        double newOffset = scrollviewer.VerticalOffset + (rectangle.Bottom - scrollviewer.ViewportHeight);
        scrollviewer.ScrollToVerticalOffset(newOffset);
    }
}

bool IsVisualChild(DependencyObject element, DependencyObject searchChildElement)
{
    if (element == searchChildElement)
        return true;
    // recursively process nested children in the visual tree 
    int children = VisualTreeHelper.GetChildrenCount(element);
    for (int i = 0; i < children; i++)
    {
        DependencyObject child = VisualTreeHelper.GetChild(element, i);
        if (IsVisualChild(child, searchChildElement))
            return true;
    }
    return false;
}

private void txtbox6_GotFocus(object sender, RoutedEventArgs e)
{
    txtbox6.Focus();
    ScrollToFocused(sc);
} 

しかし同じ結果...あなたの助けは大歓迎です。

4

1 に答える 1