Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 232
Erik Mandke Avatar asked Jun 03 '14 13:06

Erik Mandke


2 Answers

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

like image 61
dkozl Avatar answered Sep 20 '22 08:09

dkozl


Set The Property in datagrid

<DataGrid AutoGenerateColumns="False" Grid.Column="0" Grid.Row="0"
      ScrollViewer.CanContentScroll="True" 
      ScrollViewer.VerticalScrollBarVisibility="Auto"
      ScrollViewer.HorizontalScrollBarVisibility="Auto">
</DataGrid>
like image 33
Dhru 'soni Avatar answered Sep 21 '22 08:09

Dhru 'soni