【发布时间】:2020-07-15 03:11:01
【问题描述】:
我正在为一个 UWP 应用程序构建一个自定义 XAML 控件,该应用程序严重依赖具有捕捉点的 ScrollViewer。
我非常希望将绑定到控件的内容虚拟化,因此我使用了 ItemsControl。但是,当我在 ItemsControl 中使用 VirtualizingStackPanel,然后在 ScrollViewer 上调用 ChangeView() 到特定的 HorizontalOffset 时,滚动到新偏移量时的动画效果被禁用(它只是直接跳转到偏移量)。如果我只是将 VirtualizingStackPanel 替换为 StackPanel(无虚拟化),则水平动画会起作用。
问题:有谁知道如何使用 VirtualizingStackPanel和在更改偏移量时启用水平动画?
这是调整水平偏移量的 C#(customScrollViewer 是通过树爬网访问的,因为它是 ControlTemplate 样式的一部分):
customScrollViewer.ChangeView(500, null, null, false);
这里是 ItemsControl 的 XAML 样式:
<Style x:Key="ItemsControlSnapStyle" TargetType="ItemsControl">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ItemsControl">
<ScrollViewer
x:Name="customScrollViewer"
VerticalScrollBarVisibility="Disabled"
HorizontalScrollBarVisibility="Auto"
HorizontalSnapPointsType="Mandatory">
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
谢谢!
【问题讨论】: