我想不出如何让itemControl的项目激活项目控件的水平滚动条。我的场景是只有一个项目。当itemSource中存在多个项目时,会出现滚动条。但是项模板的构建方式是,每个项都足够长,可以超出父项的宽度。我假设我将需要使用Pixel作为我的滚动单元,但这并没有什么不同。
<ItemsControl Grid.Row="1" ItemsSource="{Binding LAndUDataPoints[0].Models, Mode=OneWay}" HorizontalContentAlignment="Stretch" ItemTemplate="{StaticResource LAndUItemTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate >
<VirtualizingStackPanel Orientation="Horizontal" ScrollUnit="Pixel" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>

发布于 2019-01-03 02:51:09
ItemsControl (和ListBox)执行智能滚动(滚动时跳到每个项目),但对于一个项目,它只会停留在第一个项目的开头(不需要滚动条,因为在可见窗口之外没有第二个项目)。
如果你想要一个更平滑的滚动和保持虚拟化,你应该切换到使用TreeView,例如:
<TreeView Grid.Row="1" ItemsSource="{Binding LAndUDataPoints[0].Models, Mode=OneWay}" HorizontalContentAlignment="Stretch" ItemTemplate="{StaticResource LAndUItemTemplate}">
<TreeView .ItemsPanel>
<ItemsPanelTemplate >
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</TreeView .ItemsPanel>
</TreeView >在这种情况下,您不需要在VirtualizingStackPanel上使用ScrollUnit="Pixel"。
https://stackoverflow.com/questions/53961153
复制相似问题