wpf - ScrollViewer 在 DockPanel 中不起作用
问题描述
我有下面的代码示例,其行为如下图所示。
<DockPanel LastChildFill="False" >
<ScrollViewer DockPanel.Dock="Top">
<ItemsControl>
<Label Content ="First" BorderBrush="Violet" BorderThickness="2"/>
<Label Content ="Second" BorderBrush="Black" BorderThickness="2"/>
<Label Content ="Third" BorderBrush="Yellow" BorderThickness="2" />
<Label Content ="Fourth" BorderBrush="Green" BorderThickness="2"/>
<Label Content ="Fifth" BorderBrush="Maroon" BorderThickness="2"/>
</ItemsControl>
</ScrollViewer>
<Button Height="50" DockPanel.Dock="Top">button</Button>
</DockPanel>
这里的问题是 Button 在调整大小期间被剪裁,然后 ScrollViewer 才激活。当空间不足时,如何防止 Button 剪辑和调整 ScrollViewer 的大小?
解决方案
交换 DockPanel 子项的顺序并设置LastChildFill
为True
使 ScrollViewer 填充。将 Button 停靠在Bottom
并将 Dockpanel 设置VerticalAlignment
为Top
。
<DockPanel LastChildFill="True" VerticalAlignment="Top">
<Button Height="50" DockPanel.Dock="Bottom">button</Button>
<ScrollViewer>
<ItemsControl>
<Label Content ="First" BorderBrush="Violet" BorderThickness="2"/>
<Label Content ="Second" BorderBrush="Black" BorderThickness="2"/>
<Label Content ="Third" BorderBrush="Yellow" BorderThickness="2"/>
<Label Content ="Fourth" BorderBrush="Green" BorderThickness="2"/>
<Label Content ="Fifth" BorderBrush="Maroon" BorderThickness="2"/>
</ItemsControl>
</ScrollViewer>
</DockPanel>
推荐阅读
- python - Python - 如何绘制 3D 数组?
- php - 如何在自动精选图片帖子中添加 alt 标签?
- appium - 是否可以使用 Android Emulator 扫描图像?
- javascript - Internet Explorer 11 不支持滚动方法
- popup - 需要在弹出窗口中停止视频的自动播放
- node.js - Nodejs res.end() [和其他版本的发送响应,如 res.write() 等] 没有发送完整的字符串,介于两者之间
- amazon-s3 - CircleCI 部署到 AWS S3:我的文件的路径是什么?
- javascript - Electron-dl 使用 promise.all 进行多个同时下载
- android - 如何在共享首选项中使用 Gson 从 JSON 中删除特定集合?
- python - 安装在 ubuntu 和 windows 上的 python 中 listdir 的不同行为