更改 WPF 数据网格中滚动条的位置
我的 C# WPF 应用程序中的数据网格存在布局问题。如果由于行太多而无法在数据网格中显示我的数据网格的内容,则会显示滚动查看器(和滚动条)。这是正确的方法,我对此感到高兴。
问题是,滚动查看器在我的数据网格中的位置是错误的。滚动查看器从标题行开始,但滚动条显示在我的内容的第一行中。标题中有一个白色的矩形。这是因为我的数据网格的背景是白色的。但我的标题背景是灰色的。
我上传了一张带有红色箭头的图片来澄清我的问题。白色矩形看起来真的很难看,所以在我看来,这是更改滚动查看器位置的更好方法,因此它从内容的第一行开始。也许还有另一种可能来解决问题?
“Datagrid with Scrollviewer”-图像:
感谢您的任何提示,这将帮助我解决问题!
此致, 闪光器
I have a layout problem with a datagrid in my C# WPF application. If the content of my datagrid can't be displayed in my datagrid because there are to many rows, a scrollviewer (and scrollbar) is displayed. This is the correct way and I'm happy about it.
The problem is, that the position of the scrollviewer in my datagrid ist wrong. The scrollviewer starts in the header row, but the Scrollbar is displayed in the first row of my content. In the header there is a white retangle. This is because the background of my datagrid is white. But the background of my header is gray.
I uploaded a picture with a red arrow to clarify my problem. The white retangle looks really ugly, so in my opinion it's the better way to change the position of the scrollviewer, so it starts in the first row of the content. Maybe there is another possibility to solve the problem?
"Datagrid with Scrollviewer"-Image:
Thanks for any hints, which will help me to solve the problem!
Best regards,
Flasher
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以为你的数据网格创建自己的样式,这是一个用 Blend 制作的样式,有两个更改,
看看
PART_VerticalScrollBar
的这两个更改 ->Grid.Row="0"
和Grid.RowSpan="2"
对于包含
PART_HorizontalScrollBar
的网格 ->Grid.ColumnSpan="2"
这是完整的样式
希望这有帮助
you can make your own style for your datagrid, here is a style made with blend with two changes
look at these two changes
for
PART_VerticalScrollBar
->Grid.Row="0"
andGrid.RowSpan="2"
and for the grid that holds the
PART_HorizontalScrollBar
->Grid.ColumnSpan="2"
here is the complete style
hope this helps
我一直讨厌那个角落。最简单的方法是将
DataGrid.Background
颜色设置为标题颜色,尽管这也会为空DataGrid
的背景着色(如果它有固定的颜色)尺寸。您始终可以通过将DataGrid
放置在不拉伸其子级的控件内来避免这种情况,例如StackPanel
或带有DockPanel
code>LastChildFill="False"替代方案包括覆盖 DataGrid 或其 ScrollBar 的样式或模板部分。混乱,但有可能。
I've always hated that corner. The easiest way around it is to set your
DataGrid.Background
color to whatever your header color is, although this will also color the background of an emptyDataGrid
if it has a fixed size. You can always avoid that by placing yourDataGrid
inside a control that doesn't stretch it's children, like aStackPanel
, or aDockPanel
withLastChildFill="False"
Alternatives include overwriting styles or templates pieces of the DataGrid or it's ScrollBars. Messy, but possible.
将数据网格包含在 Scrollviewer 中并将其 HorizontalScrollBarVisibility 设置为隐藏
和 VerticalScrollBarVisibility 到 Auto.Hope 这会有所帮助。
Enclose your datagrid in Scrollviewer and set its horizontalScrollBarVisibility to hidden
and VerticalScrollBarVisibility to Auto.Hope this will help.