Search code examples
c#wpf.net-4.0scroll

WPF DataGrid horizontal scrollbar not showing


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>

And here is what I get:

enter image description here

I have also tried wrapping DataGrid with ScrollViewer. Nothing. How can I make scrollbar appear?


Solution

  • 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 :)