How to increase size of Datagrid Scrollbar?

痴心易碎 提交于 2021-01-21 10:29:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!