2013-02-13 287 views
5

與其他人一樣,我有一個DataGrid沒有顯示滾動條。我認爲我的情況是獨一無二的,我在視覺或邏輯樹中的任何地方都看不到StackPanel。我正在使用WPF Inspector查看樹。我嘗試了各種建議來設置包含網格列和行的高度和寬度,但沒有成功。我敢肯定,我錯過了一些讓內容延伸到可見區域之外的東西,但我不知道它到底是什麼。任何幫助,將不勝感激。此應用程序是一個帶有MEF應用程序的WPF Prism,DataGrid位於Prism區域中的UserControl內。WPF DataGrid不顯示滾動條和用盡可見區域

shell窗口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> 

回答

14

你必須在DataGrid中網格行,其中RowDefinition高度爲auto,這樣的網格將與測量無限高度,並安排到其DesiredSize.Height並從不顯示滾動條。看起來像網格應該在第1行或使第2行的高度爲*而不是自動。

+0

這確實解決了我的問題。謝謝安德魯。我可以發誓我嘗試了這一點。對不起,發佈這樣一個明顯的疏忽,但我相當肯定這是類似的東西,因爲沒有別的意義。 – David 2013-02-14 19:47:37