I have a WPF Datagrid, at initial stage i will assign 100 column header to Datagrid, but I am not able to horizontal scroll it to view all column headers.
DataGrid does not have any rows, ItemSource is null. How do I achieve horizontal scrolling when I have only column headers (no rows).
I binded ItemSource to a DataTable which has only column header and no rows.
How can I scroll in this scenario.
Here is a workaround for this issue that worked for me: just place the DataGrid into a ScrollViewer and make a DataTrigger to set the HorizontalScrollBarVisibility of the ScrollViewer to Visible if DataGrid has no items.
<ScrollViewer VerticalScrollBarVisibility="Disabled">
    <ScrollViewer.Style>
        <Style TargetType="ScrollViewer">
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=dataGrid, Path=HasItems}" Value="False">
                    <Setter Property="HorizontalScrollBarVisibility" Value="Visible"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </ScrollViewer.Style>
    <DataGrid Name="dataGrid"/>
</ScrollViewer>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With