Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF DataGrid Scrollbar

I'm trying to make a WPF DataGrid show scrollbars when necessary. You can see the basic XAML code of my user control below:

<Grid x:Name="Data" Grid.Column="0" VerticalAlignment="Stretch" Height="Auto" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Expander Header="Route Setup" Grid.Row="0" VerticalAlignment="Top" Background="White">
</Expander>
<Expander Header="Select Locations" Grid.Row="1" VerticalAlignment="Top" Background="White">
</Expander>
<DataGrid Grid.Row="2" ItemsSource="{Binding Locations, Mode=TwoWay}" Height="Auto" AutoGenerateColumns="False" ScrollViewer.CanContentScroll="True" 
    ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto">
</DataGrid>

This isn't working, I don't see any scroolbars when the DataGrid grows beyond the available space. I've already tried to use a scrollview around my DataGrid but that doesn't change anything.

Update

It might be important to know that the usercontrol is loaded into the LeftRegion of a shell that has the following markup:

    <Grid x:Name="LayoutRoot">
    <Grid.ColumnDefinitions >
        <ColumnDefinition Width="*" MinWidth="400" MaxWidth="600"/>
        <ColumnDefinition Width="9" />
        <ColumnDefinition Width="*" MinWidth="300" />
    </Grid.ColumnDefinitions>
    <GridSplitter x:Name="MainSplitter" HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch" Grid.Column="1"
        Margin="0" Width="9" Style="{DynamicResource gridSplitterVerticalStyle}"/>
    <ItemsControl Name="LeftRegion" Grid.Column="0" Background="Azure" Height="Auto" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch"  cal:RegionManager.RegionName="LeftRegion">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <Grid/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
    <ItemsControl  Name="RightRegion" Height="Auto" Background="DarkGreen"  VerticalAlignment="Stretch" VerticalContentAlignment="Stretch" Grid.Column="2" cal:RegionManager.RegionName="RightRegion">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <Grid/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
</Grid>

Best Regards

Jay

like image 960
Jay Avatar asked Dec 16 '22 11:12

Jay


1 Answers

In your grid named "Data", remove the Height="Auto" from the third RowDefinition. At least one row must have the "*" height (which is the default) to take the remaining available space.

like image 160
Mart Avatar answered Dec 19 '22 01:12

Mart