是否可以在没有行的 DataGrid 中显示水平滚动条?
我希望允许用户水平滚动 DataGrid
,即使 DataGrid
中没有行。只是为了让他们找出 DataGrid 中存在的所有列。可以做吗?
I would like to allow users to scroll a DataGrid
horizontally even if there are no row(s) in the DataGrid
. Just to allow them to find out all the columns that exists in DataGrid
. Is it possible to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不确定是否没有重新定义模板。我能够显示滚动条(通过直接访问它),但不能实际滚动。我最终采纳了类似帖子中的建议,即添加虚拟行并在没有行时将行高设置为 0。它很丑,但是很有效。
I'm not sure if it is without redefining the template. I was able to get the scrollbar to show up (by accessing it directly) but not to actually scroll. I ended up going with the suggestion in a similar post of adding a dummy row and setting the row height to 0 when there are no rows. It's ugly, but it works.
尝试将
DataGrid
包装在ScrollViewer
中,将HorizontalScrollBarVisibility
强制设置为Visible
,并将以下属性添加到DataGrid
:应该可以解决问题
Try to wrap your
DataGrid
in aScrollViewer
, with theHorizontalScrollBarVisibility
forced toVisible
, and add the following property to theDataGrid
:Should do the trick
您可以尝试将
DataGrid
的MaxWidth
绑定到父元素(Control/Window/Grid
)的ActualWidth
/ETC。)。You can try binding the
MaxWidth
of theDataGrid
to theActualWidth
of the parent element (Control/Window/Grid
/etc.).您可以尝试使用
ScrollViewer.HorizontalScrollBarVisibility="Visible"
强制水平滚动条,或者如果失败,您可以禁用DataGrid
内的滚动并将其包装到ScrollViewer< /代码>。
You can try to force the horizontal scrollbar with
ScrollViewer.HorizontalScrollBarVisibility="Visible"
or if that fails you can disable scrolling insideDataGrid
and wrap it into aScrollViewer
.