WPF DataGrid水平滚动条未显示 [英] WPF DataGrid horizontal scrollbar not showing
本文介绍了WPF DataGrid水平滚动条未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用4列创建了简单的DataGrid,这些列超出了DataGrid的范围,并且没有显示水平滚动条。我尝试为每列设置宽度,但没有任何改变。这是我的XAML:
I have created simple DataGrid with 4 columns, which go outside the bounds of DataGrid, and horizontal scrollbar is not showing. I tried setting width to each column but nothing changed. Here is my XAML:
<Window x:Class="WPFTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<DataGrid Height="200" Width="200" HorizontalScrollBarVisibility="Visible">
<DataGrid.Columns>
<DataGridTextColumn Header="Column 1" />
<DataGridTextColumn Header="Column 2" />
<DataGridTextColumn Header="Column 3" />
<DataGridTextColumn Header="Column 4" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
这就是我得到的:
我也尝试过用ScrollViewer包装DataGrid。没有。我该如何使滚动条出现?
I have also tried wrapping DataGrid with ScrollViewer. Nothing. How can I make scrollbar appear?
推荐答案
我认为当 Datagrid
为空, ScrollViewer
无法处理任何内容。尝试通过添加 ItemsSource
来填充列,因此应该显示滚动:)
I think that when the Datagrid
is empty, the ScrollViewer
doesn't handle anything. Try to fill the columns by adding an ItemsSource
, the scrolling should therefore appear :)
这篇关于WPF DataGrid水平滚动条未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文