6

像其他人一样,我有一个不显示滚动条的 DataGrid。我认为我的情况的独特之处在于我在视觉或逻辑树的任何地方都看不到 StackPanel。我正在使用 WPF Inspector 查看树。我尝试了各种建议来设置包含 Grid 列和行的高度和宽度,但没有成功。我确定我缺少一些东西,它允许内容延伸到可见区域之外,但我不知道它是什么。任何帮助,将不胜感激。此应用程序是带有 MEF 应用程序的 WPF Prism,DataGrid 位于 Prism 区域中的 UserControl 内。

外壳窗口 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>

用户控件 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>

4

1 回答 1

17

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.

于 2013-02-14T02:07:30.083 回答