xaml - 水平 ItemControl 项的宽度不超过 itemControl 的宽度
问题描述
我不知道如何让 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>
解决方案
( ItemsControl
and 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 >
在这种情况下,您不需要ScrollUnit="Pixel"
在VirtualizingStackPanel
.
推荐阅读
- r - 使用管道时如何为变量命名
- android - FFmpegAndroid 库在压缩后旋转视频
- android - 用于创建读取或删除电话联系人的应用程序功能
- c# - 如何在Unity中通过标签从脚本中获取非实例化的预制件?
- charts - 为 HighCharts 中的堆叠和分组列在每个条形图上添加一条线
- sql-server - 如果当前列在数据透视表中为空,则获取上一列值
- flutter - pubspec.yaml 第 21 行第 5 列出错
- java - 如何修复 Netbeans IDE 安装错误?
- java - 无法检索特定字段的列表项值
- reactjs - 在使用 React 和 Electron 登录后,构建登录并继续到主页的最佳方式是什么