是否有任何机构知道管理PivotItem内滚动查看器行为的好方法。 Scrollviewer包含一个带有6个TextBox和6个TextBlock的Stackpannel。 (见下面的代码编码器......)
我想要它的工作方式:无论我选择什么文本框...它应该保持可见,所有其他文本框应该可以在键盘显示时... ...
如果枢轴的标题消失,这没有问题......但是如果它也留在screan上也会很好...... 我尝试过边距,带有动态高度的矩形,调整RootFrame的大小,调整Pivot的大小,调整ViewScroller高度的大小...使其适合和工作......我接近调整大小的动作。但TextBox的焦点有时落在键盘的后面。
如何设置在这种情况下将所选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)
{ }
干杯,
ķ
答案 0 :(得分: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
}
}
我希望有人找到时间来完成功能并使其完美; - )
干杯,
ķ