Windows phone 7 当scrollbarvisibility设置为disabled时,如何防止Scrollviewer向后滚动?wp7
我在WP7中创建了一个Scrollviewer,其中包含3个usercontrol,每个usercontrol都作为其内容保存在XAML创建的usercontrol中。这个很好用。此scrollviewer应该能够在这些项目之间滚动,但不能让用户滚动。因此,当单击其中一个内容中的项目时,scrollviewer会根据所选项目向左或向右滑动,并将其他用户控件之一带入视图。我使用调解人来完成以下任务:Windows phone 7 当scrollbarvisibility设置为disabled时,如何防止Scrollviewer向后滚动?wp7,windows-phone-7,uiscrollview,Windows Phone 7,Uiscrollview,我在WP7中创建了一个Scrollviewer,其中包含3个usercontrol,每个usercontrol都作为其内容保存在XAML创建的usercontrol中。这个很好用。此scrollviewer应该能够在这些项目之间滚动,但不能让用户滚动。因此,当单击其中一个内容中的项目时,scrollviewer会根据所选项目向左或向右滑动,并将其他用户控件之一带入视图。我使用调解人来完成以下任务: <Grid.Resources> <Storyboard x:N
<Grid.Resources>
<Storyboard x:Name="ItemAnimation">
<DoubleAnimation x:Name="ItemAnimationContent"
Storyboard.TargetName="Mediator"
Storyboard.TargetProperty="ScrollableWidthMultiplier"/>
</Storyboard>
</Grid.Resources>
<ScrollViewer Name="ScrollableItemPanel"
Grid.Row="2"
Grid.RowSpan="3"
Grid.ColumnSpan="3"
VerticalScrollBarVisibility="Disabled"
HorizontalScrollBarVisibility="Disabled">
<StackPanel Orientation="Horizontal">
<UserControl Name="NewsListBoxControl" Width="480" />
<UserControl Name="DetailedItemControl" Width="480"/>
<UserControl Name="ExternalBrowserItemControl" Width="480"/>
</StackPanel>
</ScrollViewer>
<local:ScrollableItemAnimationMediator x:Name="Mediator"
ScrollViewer="{Binding ElementName=ScrollableItemPanel}"/>
在basic中,这也很好,我可以在项目之间导航,并将内容作为用户控件加载到项目上。但问题在于授予用户滚动的能力。在项目滚动之前,我将HittestVisibility设置为true,将horizontalscrollbarvisibility设置为visible。动画完成后,我想重新授予hittestvisibility,并再次将horizontalscrollbarvisibility设置为Disabled。后者就是问题所在:当我将horizontalscrollbarvisibility设置为Disabled时,scrollviewer会自动将stackpanel中三个项目中的第一个带回视图。我怎样才能阻止这一切?这是我用来滚动中介的代码:
private void CreateDetailedArticleItem( Dictionary<string, string> itemQuery )
{
_articleDetailPage.ItemQuery = itemQuery;
DetailedItemControl.Content = _articleDetailPage as UserControl;
Animate( _articleDetailPage, 0.0f, 0.5f, 250 );
}
private void Animate( IContentControl control, float from, float to, double milliseconds )
{
//this eventhandler will fire when the animation has completed
EventHandler handler = null;
//we take away the User Input just for the moment, so that we can animate without the user interfering. Also, we make horizontalScroll Visible
IsUserEnabled = false;
//we then set the content of the animation. Where from will it move, towards where and in what duration?
ItemAnimationContent.From = from;
ItemAnimationContent.To = to;
ItemAnimationContent.Duration = TimeSpan.FromMilliseconds( milliseconds );
//we start the animation
ItemAnimation.Begin( );
//we tell the new control that it will appear soon, so it can load its main content
control.ViewWillAppear( );
//also, we tell the currentcontrol that it will disappear soon, so it can unload its content and eventhandlers and so on
CurrentControl.ViewWillDisAppear( );
//the handler is a delegate. This way, it becomes rather easy and clean to fire the completed event, without creating a strong reference ( well, actually,
//we do create a strong reference, but as soon as it is fired, we remove it again, shhhh! ).
handler = delegate( object sender, EventArgs e )
{
//as stated, we remove the eventlistener again, so it won't keep firing all the time
ItemAnimation.Completed -= handler;
//after the animation, we tell the new control that it is now in screen, and can start downloading its data
control.ViewDidAppear( );
//at the same time, the "current" control has fully moved out of view, so it can now fully unload all its content.
CurrentControl.ViewDidDisAppear( );
//now, all we have to do is to make sure that the next time an item is being loaded, the new content is spoken to, not the old one
CurrentControl = control;
//and finally, enable the users input again, and remove the horizontal scrollbarvisibility
IsUserEnabled = true;
};
ItemAnimation.Completed += handler;
}
private bool IsUserEnabled
{
set
{
//when the user can control the scrollviewer, then the horizontal scrollvisibility is disabled, so that the user cannot move horizontally,
//otherwise, so we only make it visible when the program needs to animate.
ScrollableItemPanel.IsHitTestVisible = value;
ScrollableItemPanel.HorizontalScrollBarVisibility = value ? ScrollBarVisibility.Disabled : ScrollBarVisibility.Visible;
}
}
private void CreateDetailedArticleItem(字典项查询)
{
_articleDetailPage.ItemQuery=ItemQuery;
DetailedItemControl.Content=\u articleDetailPage作为用户控件;
制作动画(_articleDetailPage,0.0f,0.5f,250);
}
私有void动画(IContentControl控件、浮点从、浮点到、双毫秒)
{
//此eventhandler将在动画完成时激发
EventHandler=null;
//我们暂时删除用户输入,这样我们就可以在没有用户干扰的情况下制作动画。此外,我们还可以使水平滚动可见
IsUserEnabled=false;
//然后我们设置动画的内容。动画将从何处移动,移动到何处,持续多长时间?
ItemAnimationContent.From=From;
ItemAnimationContent.To=To;
ItemAnimationContent.Duration=TimeSpan.FromMillions(毫秒);
//我们开始动画
Begin();
//我们告诉新控件它将很快出现,以便它可以加载其主要内容
控件的视图将出现();
//另外,我们告诉currentcontrol它将很快消失,以便它可以卸载其内容和EventHandler等
view将消失();
//处理程序是一个委托。这样,激发已完成的事件就变得相当容易和干净,而无需创建强引用(实际上,
//我们确实创建了一个强引用,但一旦它被激发,我们就会再次删除它,嘘!)。
handler=delegate(对象发送方,事件参数)
{
//如上所述,我们再次删除eventlistener,因此它不会一直处于激活状态
ItemAnimation.Completed-=处理程序;
//动画完成后,我们告诉新控件它现在在屏幕上,并且可以开始下载它的数据
控件;ViewDidDisplay();
//同时,“当前”控件已完全移出视图,因此它现在可以完全卸载其所有内容。
CurrentControl.viewdiddemouse();
//现在,我们所要做的就是确保下一次加载一个项目时,新内容会被告知,而不是旧内容
电流控制=控制;
//最后,再次启用用户输入,并删除水平滚动条可见性
IsUserEnabled=true;
};
ItemAnimation.Completed+=处理程序;
}
私有bool是用户启用的
{
设置
{
//当用户可以控制scrollviewer时,水平滚动可见性被禁用,因此用户无法水平移动,
//否则,我们只能在程序需要设置动画时使其可见。
ScrollableItemPanel.IshittesVisible=值;
ScrollableItemPanel.HorizontalScrollBarVisibility=值?ScrollBarVisibility.Disabled:ScrollBarVisibility.Visible;
}
}
我已经问了这个问题,然后认为它已经回答了,因为我认为它已经回答了,即使用ScrollbarVisibility.Hidden而不是ScrollbarVisibility.Disabled,只有ScrollbarVisibility以这种方式保持可见,用户仍然可以滚动。有没有本地的方法来处理这个问题
任何帮助都将不胜感激。Greetz与其对抗本机控件的行为,不如使用自定义控件(包装其他控件)自己操纵项目的位置,该控件根据“选定”项目在不同视觉状态之间设置动画(调整平移变换)。是的,我确实想到了这一点(在等待回答时处理其他内容),但我认为可能存在一些本地的东西,这会节省我很多时间。但据你所知,没有办法绕过scrollviewer的这个缺陷,我想是吧?它可以说不是控件中的一个缺陷。你只是想用它来做一些不是为它设计的东西。是的,这是真的,我只是觉得ScrollbarvisiVibility提供了两种隐藏可见性的方法,一种是不阻止滚动(我认为它只是隐藏了指示器滚动条),另一种是在将其设置为“不可见”后立即使其滚动回顶部。无论如何,我现在正在使用您建议的方法。谢谢=3