Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF DataGrid not showing scrollbars and running out of visible area

Like others I have a DataGrid that is not showing scrollbars. What I think is unique to my situation is that I do not see a StackPanel anywhere in the visual or logical tree. I am using WPF Inspector to view the trees. I have tried various suggestions to set the height and width of the containing Grid columns and rows with no success. I'm certain there is something I'm missing that is allowing the content to extend beyond the visible area but I cannot tell what it is yet. Any help would be appreciated. This application is a WPF Prism with MEF app and the DataGrid is within a UserControl which is in a Prism region.

Shell Window XAML:

<Window>
  <Grid x:Name="GridOuterShell">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <ribbon:Ribbon Grid.Row="0" >
        ...
    </ribbon:Ribbon>

    <Grid x:Name="GridShellContent" Grid.Row="1">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="350" MinWidth="300"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>


        <local:RegionBorderControl Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" Margin="2,2,8,2" RegionName="{Binding MainRegionDisplayName}"
                               Style="{DynamicResource RegionBorderControlStyle}">
        <ContentControl prism:RegionManager.RegionName="MainRegion"
                        VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"/>

        </local:RegionBorderControl>


        <GridSplitter Grid.Row="0" Grid.Column="1" Grid.RowSpan="3" HorizontalAlignment="Center" VerticalAlignment="Stretch"
                  Width="3" ShowsPreview="True" ResizeDirection="Columns" />

        <local:RegionBorderControl Grid.Row="0" Grid.Column="2" RegionName="{Binding RightTopRegionDisplayName}"
                               Style="{DynamicResource RegionBorderControlStyle}">
        <ContentControl prism:RegionManager.RegionName="RightTopRegion"
                        VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"/>

        </local:RegionBorderControl>

        <GridSplitter Grid.Row="1" Grid.Column="3" HorizontalAlignment="Stretch" VerticalAlignment="Center"
                  Height="3" ShowsPreview="true" ResizeDirection="Rows" ResizeBehavior="PreviousAndNext" Background="Silver"/>

        <local:RegionBorderControl Grid.Row="2" Grid.Column="2" RegionName="{Binding RightBottomRegionDisplayName}"
                               Style="{DynamicResource RegionBorderControlStyle}">
            <ContentControl prism:RegionManager.RegionName="RightBottomRegion"/>

        </local:RegionBorderControl>

    </Grid>

    <StatusBar Grid.Row="2">
        ...
    </StatusBar>

  </Grid>
</Window>

UserControl XAML:

<UserControl>

<Grid x:Name="GridMain">
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition />
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <DockPanel Grid.Row="0" LastChildFill="False" HorizontalAlignment="Stretch" Width="Auto" >
            <ToolBar x:Name="tbToolBar" DockPanel.Dock="Left" Background="{x:Null}">
                ...
            </ToolBar>
        </DockPanel>

        <DataGrid AutoGenerateColumns="False" Grid.Row="2" Name="DataGridList" ItemsSource="{Binding MyItems}" IsReadOnly="True" CanUserResizeRows="False" SelectionMode="Single" 
                    SelectedItem="{Binding Path=SelectedDataGridRecord, Mode=TwoWay}" Style="{StaticResource DataGridDefault}" >
            <DataGrid.Columns>
                ...
            </DataGrid.Columns>
        </DataGrid>

    </Grid>

like image 424
David Avatar asked Feb 13 '13 19:02

David


1 Answers

You have the DataGrid in a Grid row where the RowDefinition Height is auto so the grid will be measured with an infinite height and be arranged to its DesiredSize.Height and never show scrollbars. Seems like the grid should be in row 1 or make the height of row 2 to be * instead of auto.

like image 141
AndrewS Avatar answered Nov 01 '22 10:11

AndrewS