Windows phone 7 禁用滚动时如何保持滚动位置
在我的win phone 7应用程序中,我想禁用列表框中的垂直滚动。但是当我使用Windows phone 7 禁用滚动时如何保持滚动位置,windows-phone-7,listbox,scroll,Windows Phone 7,Listbox,Scroll,在我的win phone 7应用程序中,我想禁用列表框中的垂直滚动。但是当我使用 listbox.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled); 列表框滚动到顶部。如何在禁用滚动时保持滚动位置 编辑:我正在考虑在listbox处理事件之前通过吞咽事件来禁用滚动。但当我试图处理操纵开始和操纵完成时,我有一个例外。我应该处理哪些事件以使listbox无法滚动? 当我在
listbox.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled);
列表框滚动到顶部。如何在禁用滚动时保持滚动位置
编辑:我正在考虑在listbox处理事件之前通过吞咽事件来禁用滚动。但当我试图处理操纵开始和操纵完成时,我有一个例外。我应该处理哪些事件以使listbox无法滚动?
当我在代码中将操纵开始、操纵增量和操纵完成标记为已处理时,此堆栈跟踪出现空异常:
at Microsoft.Phone.Gestures.GestureHelper.ReleaseMouseCaptureAtGestureOrigin()
at Microsoft.Phone.Gestures.GestureHelper.NotifyMove(InputDeltaArgs args)
at Microsoft.Phone.Gestures.ManipulationGestureHelper.Target_ManipulationDelta(Object sender, ManipulationDeltaEventArgs e)
at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
at Microsoft.Xna.Framework.Input.UnsafeNativeMethods.CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
at Microsoft.Xna.Framework.Input.SafeNativeMethods.CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
at Microsoft.Xna.Framework.Input.WindowMessageHooker.Hook.WndProc(IntPtr msgWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
编辑:我发现当禁用滚动时,默认列表框可以按我所希望的方式工作。但是我的listbox有一个自定义模板,其中包含一个堆栈,用于保存ItemPresenter以禁用UI虚拟化。在这种情况下,禁用滚动时,列表框会自动滚动到顶部
编辑:以下是列表框的模板:
<phone:PhoneApplicationPage.Resources>
<Style x:Key="ListBoxStyle1" TargetType="ListBox">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<ScrollViewer x:Name="ScrollViewer" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" Padding="{TemplateBinding Padding}">
<StackPanel Orientation="Vertical" Width="468">
<ItemsPresenter d:LayoutOverrides="Width"/>
</StackPanel>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</phone:PhoneApplicationPage.Resources>
和xaml:
<ListBox x:Name="MainListBox" Margin="0,0,-12,0" ItemsSource="{Binding Items}" SelectionChanged="MainListBox_SelectionChanged" Style="{StaticResource ListBoxStyle1}" GotFocus="gotfocus" LostFocus="lostfocus">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432">
<TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
在gotfocus和lostfocus函数中,我分别禁用和启用滚动。此列表框来自默认的数据绑定应用程序。当我向下滚动并单击一个项目时,列表框会滚动到顶部。如果我不使用堆栈来保存ItemPresenter,则不会发生这种情况。您可以执行以下操作:
ScrollViewer.SetVerticalScrollBarVisibility(listbox, ScrollBarVisibility.Disabled);
您可以这样做:
ScrollViewer.SetVerticalScrollBarVisibility(listbox, ScrollBarVisibility.Disabled);
是否可以将属性IshitteVisible设置为false以禁用滚动?是否可以将属性IshitteVisible设置为false以禁用滚动?我有一个正在处理的小项目,也有一个自定义模板列表框。我测试了以下代码,这似乎对我很好:
ScrollViewer.SetVerticalScrollBarVisibility(YourListBox, ScrollBarVisibility.Disabled);
YourListBox.ScrollIntoView(YourListBox.SelectedItem);
我有一个小项目,我的工作,也与自定义模板列表框。我测试了以下代码,这似乎对我很好:
ScrollViewer.SetVerticalScrollBarVisibility(YourListBox, ScrollBarVisibility.Disabled);
YourListBox.ScrollIntoView(YourListBox.SelectedItem);
谢谢,但这仍然会使列表框滚动到顶部。我想在禁用滚动后保留滚动位置。我刚刚尝试过,它似乎对我很好。你能发布你的代码吗?嗨,键盘P,你是对的,默认的列表框工作正常,但我有一个自定义模板的列表框。请查看我更新的问题:-)谢谢,但这仍然会使列表框滚动到顶部。我想在禁用滚动后保留滚动位置。我刚刚尝试过,它似乎对我很好。你能发布你的代码吗?嗨,键盘P,你是对的,默认的列表框工作正常,但我有一个自定义模板的列表框。请查看我更新的问题:-)您可以显示列表框的XAML吗?是的,我已经更新了问题=)您可以显示列表框的XAML吗?是的,我已经更新了问题=)嗯,不,因为我需要与列表框项=)嗯,不,因为我需要与列表框项=)交互)