0

有没有人知道管理 PivotItem 内滚动查看器行为的好方法。而 Scrollviewer 包含一个带有 6 个 TextBoxes 和 6 个 TextBlockes 的 Stackpannel。(见下面我的代码ferder ...)

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

如果枢轴的标题消失也没问题...但是如果它也保持在屏幕上会很好...我尝试过边距,具有动态高度的矩形,调整RootFrame的大小,调整Pivot的大小,调整大小ViewScroller 高度...使其适合并工作...我接近调整大小操作。但是 TextBox 的焦点有时在键盘后面。

在这种情况下,如何设法将选定的文本框滚动/移动到我的屏幕顶部...

我希望你们中的一个可以帮助我...

这是我的 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>

这是我的代码隐藏:

private void appBarRegisterButton_Click_1(object sender, EventArgs e)
    { }
private void TextBlock_GotFocus_1(object sender, RoutedEventArgs e)
    { }
private void TextBlock_LostFocus_1(object sender, RoutedEventArgs e)
    { }

干杯,

ķ

4

1 回答 1

2

我能得到的最接近的解决方案如下。在我的应用程序流程中管理此解决方案的使用。它还不完美。我会说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>

背后的代码:

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
    }
}

我希望有人能抽出时间来完成功能并使其完美;-)

干杯,

ķ

于 2013-05-29T08:59:05.330 回答