我有一个带数据网格的WPF窗口。我需要向datagrid添加水平滚动条。我已将datagrid的宽度和高度设置为auto,以便在窗口大小更改时它也会更改大小。
显然,滚动条仅在宽度和高度未设置为自动时才起作用。我该如何解决?
<DataGrid x:Name="List_DataGrid" IsSynchronizedWithCurrentItem="True" Margin="190,0,0.2,0" Grid.ColumnSpan="2" HorizontalScrollBarVisibility="Auto">
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Background" Value="Gray"/>
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="BorderThickness" Value="0,0,1,2"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Header=" First Name " Width="110"/>
<DataGridTextColumn Header=" Surname " Width="110"/>
<DataGridTextColumn Header=" DOB " Width="110"/>
<DataGridTextColumn Header=" Age " Width="110"/>
<DataGridTextColumn Header=" Email " Width="110"/>
<DataGridTextColumn Header=" Contact Number " Width="110"/>
<DataGridTextColumn Header=" Emergency Number " Width="*"/>
</DataGrid.Columns>
</DataGrid>