Windows phone 7 在Pivot行为中包含文本框的Scrollviewer使文本框在keybord下消失

Windows phone 7 在Pivot行为中包含文本框的Scrollviewer使文本框在keybord下消失,windows-phone-7,windows-phone-8,Windows Phone 7,Windows Phone 8,是否有人知道在数据透视项中管理scrollviewer行为的好方法。而Scrollviewer包含一个带有6个文本框和6个文本块的堆栈窗格。(见下面我的代码ferder…) 我希望它的工作方式:无论我选择什么文本框。。。当显示keybord时,它应该保持可见,并且所有其他文本框都应该可以访问 如果轴的标题消失,则没有问题。。。但如果它也留在斯克雷恩那就太好了。。。 我尝试过边距、动态高度的矩形、根框的大小、轴的大小、视图滚动条高度的大小。。。要使它适合并工作。。。我接近于调整大小的动作。但文本框

是否有人知道在数据透视项中管理scrollviewer行为的好方法。而Scrollviewer包含一个带有6个文本框和6个文本块的堆栈窗格。(见下面我的代码ferder…)

我希望它的工作方式:无论我选择什么文本框。。。当显示keybord时,它应该保持可见,并且所有其他文本框都应该可以访问

如果轴的标题消失,则没有问题。。。但如果它也留在斯克雷恩那就太好了。。。 我尝试过边距、动态高度的矩形、根框的大小、轴的大小、视图滚动条高度的大小。。。要使它适合并工作。。。我接近于调整大小的动作。但文本框的焦点有时在键盘后面

如何在这种情况下将所选文本框滚动/移动到屏幕顶部

我希望你们中的一个能帮助我

这里是我的XAML代码:

<Grid x:Name="LayoutRoot"
      Background="Transparent">

    <!--Pivot Control-->
    <phone:Pivot Title="MY APPLICATION"
                 x:Name="PivotRoot">
        <phone:PivotItem Header="first"
                         x:Name="PivotFirst">
            <ScrollViewer x:Name="Scroller">
                <StackPanel Background="Orange">

                    <TextBlock Text="hoi" />
                    <TextBox GotFocus="TextBlock_GotFocus_1"
                             LostFocus="TextBlock_LostFocus_1"></TextBox>
                    <TextBlock Text="hoi" />
                    <TextBox GotFocus="TextBlock_GotFocus_1"
                             LostFocus="TextBlock_LostFocus_1"></TextBox>
                    <TextBlock Text="hoi" />
                    <TextBox GotFocus="TextBlock_GotFocus_1"
                             LostFocus="TextBlock_LostFocus_1"></TextBox>
                    <TextBlock Text="hoi" />
                    <TextBox GotFocus="TextBlock_GotFocus_1"
                             LostFocus="TextBlock_LostFocus_1"></TextBox>
                    <TextBlock Text="hoi" />
                    <TextBox GotFocus="TextBlock_GotFocus_1"
                             LostFocus="TextBlock_LostFocus_1"></TextBox>

                </StackPanel>
            </ScrollViewer>
        </phone:PivotItem>
    </phone:Pivot>
</Grid>


<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar x:Name="xxxx"
                          IsVisible="True"
                          IsMenuEnabled="True">
        <shell:ApplicationBarIconButton x:Name="appBarRegisterButton"
                                        IconUri="/Images/next.png"
                                        Text="Login"
                                        Click="appBarRegisterButton_Click_1"
                                        IsEnabled="True" />
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
干杯


K

我能得到的最接近的解决方案如下。在我的应用程序流中管理此解决方案的使用。它还没有完成。我会说95%。。。现在最大的问题是管理我用过的“矩形‘Keybordfiller’”的“动态出现和消失”。。。我觉得这很容易。。。不幸的是我没能做到。。。请随意使用它并加以改进以实现它。。。这将帮助很多人解决这个难题

MainPage.Xaml:

<phone:PhoneApplicationPage x:Class="PivotApp1.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:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
                        FontFamily="{StaticResource PhoneFontFamilyNormal}"
                        FontSize="{StaticResource PhoneFontSizeNormal}"
                        Foreground="{StaticResource PhoneForegroundBrush}"
                        SupportedOrientations="Portrait"
                        Orientation="Portrait"
                        shell:SystemTray.IsVisible="True">

<Grid x:Name="LayoutRoot"
      Background="Transparent">

    <!--Pivot Control-->
    <phone:Pivot Title="MY APPLICATION"
                 x:Name="PivotRoot">
        <phone:PivotItem Header="first"
                         x:Name="PivotFirst">
            <ScrollViewer x:Name="Scroller">
                <StackPanel Background="Orange">
                    <TextBlock Text="hey" />
                    <TextBox GotFocus="TextBlock_GotFocus" />
                    <TextBlock Text="how" />
                    <TextBox GotFocus="TextBlock_GotFocus" />
                    <TextBlock Text="are" />
                    <TextBox GotFocus="TextBlock_GotFocus" />
                    <TextBlock Text="you" />
                    <TextBox GotFocus="TextBlock_GotFocus" />
                    <TextBlock Text="doing" />
                    <TextBox GotFocus="TextBlock_GotFocus" />
                    <Rectangle x:Name="Keybordfiller"
                               Height="350" />
                </StackPanel>
            </ScrollViewer>
        </phone:PivotItem>
    </phone:Pivot>
</Grid>

<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar x:Name="Xxxx"
                          IsVisible="True"
                          IsMenuEnabled="True">
        <shell:ApplicationBarIconButton x:Name="AppBarRegisterButton"
                                        IconUri="/Assets/Tiles/IconicTileSmall.png"
                                        Text="Login"
                                        Click="appBarRegisterButton_Click"
                                        IsEnabled="True" />
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
我希望有人能抽出时间来完成功能并使其完美;-)

干杯

K

<phone:PhoneApplicationPage x:Class="PivotApp1.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:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
                        FontFamily="{StaticResource PhoneFontFamilyNormal}"
                        FontSize="{StaticResource PhoneFontSizeNormal}"
                        Foreground="{StaticResource PhoneForegroundBrush}"
                        SupportedOrientations="Portrait"
                        Orientation="Portrait"
                        shell:SystemTray.IsVisible="True">

<Grid x:Name="LayoutRoot"
      Background="Transparent">

    <!--Pivot Control-->
    <phone:Pivot Title="MY APPLICATION"
                 x:Name="PivotRoot">
        <phone:PivotItem Header="first"
                         x:Name="PivotFirst">
            <ScrollViewer x:Name="Scroller">
                <StackPanel Background="Orange">
                    <TextBlock Text="hey" />
                    <TextBox GotFocus="TextBlock_GotFocus" />
                    <TextBlock Text="how" />
                    <TextBox GotFocus="TextBlock_GotFocus" />
                    <TextBlock Text="are" />
                    <TextBox GotFocus="TextBlock_GotFocus" />
                    <TextBlock Text="you" />
                    <TextBox GotFocus="TextBlock_GotFocus" />
                    <TextBlock Text="doing" />
                    <TextBox GotFocus="TextBlock_GotFocus" />
                    <Rectangle x:Name="Keybordfiller"
                               Height="350" />
                </StackPanel>
            </ScrollViewer>
        </phone:PivotItem>
    </phone:Pivot>
</Grid>

<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar x:Name="Xxxx"
                          IsVisible="True"
                          IsMenuEnabled="True">
        <shell:ApplicationBarIconButton x:Name="AppBarRegisterButton"
                                        IconUri="/Assets/Tiles/IconicTileSmall.png"
                                        Text="Login"
                                        Click="appBarRegisterButton_Click"
                                        IsEnabled="True" />
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Navigation;

namespace PivotApp1
{
    public partial class MainPage 
    {
    public MainPage()
    {
        InitializeComponent();
        DataContext = App.ViewModel;
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        if (!App.ViewModel.IsDataLoaded)
        {
            App.ViewModel.LoadData();
        }
    }

    private void appBarRegisterButton_Click(object sender, EventArgs e)
    {
        //TODO: do some action with the button click
    }

    private void TextBlock_GotFocus(object sender, RoutedEventArgs e)
    {
        ScrollToControl((FrameworkElement)sender);
    }

    /// The issue to make it 100% fine For some reason it is not possible to make the Rectangle "Keybordfiller" Dynamically appear and disappear
    /// to have this issue solved...
    /// 
    /// When you use this code and manage to make it work 100%... 
    /// Please post your code/solution at: http://social.msdn.microsoft.com/Forums/en-US/wpdevelop/thread/b6fb4623-2fd3-459e-8c80-6ac2a77ee849/#a1f7d0fc-289c-40c9-8716-06e90c9dacd1
    /// 

    #region 90% fix of 'ScrollViewer with stackpannel full of Textboxes' handling in Pivot
    //TODO: Manage to make the Rectangle "Keybordfiller" appear and disappear Dynamically on the stackpannel

    private void ScrollToControl(FrameworkElement ui)
    {
        var currentoffset = Scroller.VerticalOffset;
        var y = GetVerticalOffset(ui, Scroller);
        Scroller.ScrollToVerticalOffset(y + currentoffset - 30);
        Scroller.UpdateLayout();
    }

    private double GetVerticalOffset(FrameworkElement child, ScrollViewer scrollViewer)
    {
        GeneralTransform focusedVisualTransform = child.TransformToVisual(scrollViewer);
        var topLeft = focusedVisualTransform.Transform(new Point(0, 0));
        return topLeft.Y;
    }

        #endregion
    }
}