2012-10-18 69 views
0

我在擴展器中有一個數據網格,gatagrid有超過10列。然後應該滾動擴展器
中的數據網格。但無法滾動查看其他列。我的代碼如下。WPF在擴展器中滾動數據網格

   <Expander Header="Attribute" VerticalAlignment="Top" Grid.Row="1" > 
        <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible" CanContentScroll="True" Grid.Row="1" > 
          <DataGrid DataContext="{Binding}" Height="257" ItemsSource="{Binding}" MinHeight="200" Name="gridview1" Grid.Row="2" Grid.Column="0" 
          VerticalAlignment="Bottom" IsReadOnly="True"></DataGrid> 
        </ScrollViewer> 
       </Expander> 
+0

Horizo​​ntalScrollBarVisibility =「Disabled」將其更改爲可見? – mcalex

+0

它沒有工作..我只是看到滾動條壞它被隱藏滾動@mcalex – Isi

+0

@Isi我的解決方案爲你工作嗎? – Sisyphe

回答

2

DataGrid在其ControlTemplate中嵌入了ScrollViewer。

所以,你可以做兩件事情:

如果你真的想用自己的ScrollViewer(但請注意,這樣做,你將失去像DataGrid的虛擬化功能)此代碼應工作:

<Expander Header="Attribute" VerticalAlignment="Top" Grid.Row="1" > 
    <ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" CanContentScroll="False" Grid.Row="1" > 
     <DataGrid Height="257" MinHeight="200" Name="gridview1" Grid.Row="2" Grid.Column="0" 
         VerticalAlignment="Bottom" IsReadOnly="True"> 
      <DataGrid.Style> 
       <Style> 
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" /> 
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled" /> 
       </Style> 
      </DataGrid.Style> 
     </DataGrid> 
    </ScrollViewer> 
</Expander> 

不過,我勸你只需做到這一點:

<Expander Header="Attribute" VerticalAlignment="Top" Grid.Row="1" > 
     <DataGrid Height="257" MinHeight="200" Name="gridview1" Grid.Row="2" Grid.Column="0" VerticalAlignment="Bottom" IsReadOnly="True"> 
      <DataGrid.Style> 
       <Style> 
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Visible" /> 
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Visible" /> 
       </Style> 
      </DataGrid.Style> 
    </DataGrid> 
</Expander> 

的DataGrid.Style甚至不應該是必要的。