开发者

WPF DataGrid Scrollbar

I'm trying to make a WPF开发者_如何学Python 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


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.


Solved it. I needed to remove Height="Auto" from the thrird RowDefinition.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜