问题
I have a Datagrid that displays the data on Runtime, and as it has lot of data it itself brings scrollbar on it, but the size is smaller. Can anyone tell how to change size of scrollbar and make it bigger ?
<DataGrid x:Name="DgUnitVerReefer" HorizontalAlignment="Center" SelectionMode="Single" SelectionUnit="FullRow" Margin="20,94,26,0" IsReadOnly="True" AutoGenerateColumns="False" Visibility="Visible" VerticalAlignment="Top" Height="334" HorizontalGridLinesBrush="#FFA4C4EA" FontFamily="Microsoft New Tai Lue" AlternatingRowBackground="#FFA4C4EA" MouseDoubleClick="DgUnitVerReefer_MouseDoubleClick" FontSize="16" Width="387">
<DataGrid.Columns>
<DataGridTextColumn Header="" Binding="{Binding Path= UNIT_NUMBER}" Width="350" />
</DataGrid.Columns>
</DataGrid>
and then on window_loaded in load data and assign to datagrid.
DgUnitVerReefer.DataContext = objVerifyUnit.DtLovReefer.DefaultView;
DgUnitVerReefer.ItemsSource = objVerifyUnit.DtLovReefer.DefaultView;
DgUnitVerReefer.DisplayMemberPath = "UNIT_NUMBER";
DgUnitVerReefer.SelectedValuePath = "UNI_ID";
on running it display scrollbar with smaller size, how to change its size ?
回答1:
You can apply style for the ScrollBar
type at the DataGrid
level. We should use a Trigger
against the Orientation
property to apply style to the vertical scrollbar only:
<DataGrid.Resources>
<Style TargetType="ScrollBar">
<Style.Triggers>
<Trigger Property="Orientation" Value="Vertical">
<Setter Property="Width" Value="50"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
For horizontal scrollbar, we need to set the Height
instead, and the Value
for the trigger is Horizontal
.
来源:https://stackoverflow.com/questions/24904062/how-to-increase-size-of-datagrid-scrollbar