Search code examples
c#wpfdatagridscrollbar

WPF Datagrid - Not showing any Scrollbar


My Datagrid has a binding on an ObservableCollection and gets filled after grouping some values fetched by EF.

My Problem is, that the datagrid-height grows beyond the window size. Does anyone know how to get that fixed... I almost googled myself to death.. :o

<UserControl x:Class="UltranizerV2.Views.Storage.InventoryList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d">
    <Grid>
        <Grid.RowDefinitions>

            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="25"></RowDefinition>
        </Grid.RowDefinitions>


        <DockPanel  Grid.Row="0" >
            <DataGrid ItemsSource="{Binding PresentableInventoryItems}" VerticalAlignment="Stretch" AutoGenerateColumns="False">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Produkttitel" Width="350" Binding="{ Binding ProductTitle}"/>
                <DataGridTextColumn Header="Sku" Width="100" Binding="{ Binding Sku}" />
                <DataGridTextColumn Header="Menge" Width="60"  Binding="{ Binding Quantity}" />
            </DataGrid.Columns>    
            </DataGrid>
        </DockPanel>
        <Label Grid.Row="1">Arsch</Label>
        </Grid>

</UserControl>

Solution

  • To sum up comments your control looks fine which would suggest that the problem is somewhere up the visual tree. Most likely InventoryList, or one of its parents, it's placed in control that gives its children infinite amount of space to grow like StackPanel, ScrollViewer or Canvas. Because of that DataGrid can grow to accommodate all item hence not scroll bar is visible.

    Remove that control or replace it with one that limits the size of its children