和其他人一样,我有一个没有显示滚动条的DataGrid。我认为我的情况所独有的是我在视觉或逻辑树中的任何地方都看不到StackPanel。我正在使用WPF Inspector来查看树。我已经尝试了各种建议来设置包含Grid列和行的高度和宽度但没有成功。我确定有一些我遗漏的内容是允许内容延伸到可见区域以外但我还不知道它到底是什么。任何帮助,将不胜感激。此应用程序是带有MEF应用程序的WPF Prism,DataGrid位于Prism区域的UserControl中。
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>
答案 0 :(得分:16)
您在网格行中有DataGrid,其中RowDefinition高度是自动的,因此网格将以无限高度进行测量并安排到其DesiredSize.Height并且永远不会显示滚动条。似乎网格应该在第1行或者第2行的高度为*而不是auto。