我在网格上有两个DataGrid,其中一个DataGrid恰好位于另一个DataGrid之下,这两个DataGrid共享相同的列标题,我想对两个DataGrid使用一个滚动条(Horizontal Scroll bar) 。我怎样才能做到这一点 ??
<Grid>
<DataGrid Name="StatusGrid"
Height="Auto"
Width="Auto"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserReorderColumns="False" />
<DataGrid AutoGenerateColumns="False"
Height="auto"
Width="auto"
Margin="0,73,0,10"
Name="heatMap"
IsReadOnly="True"
CanUserReorderColumns="False"
CanUserSortColumns="False"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ItemsSource="{Binding HeatMapCollection}"
Background="AliceBlue" />
</Grid>
最佳答案
尝试像使用ScrollViewer
<ScrollViewer CanContentScroll="True"
HorizontalScrollBarVisibility="Visible"
VerticalScrollBarVisibility="Visible">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<DataGrid Grid.Row="0"
Name="StatusGrid"
Height="Auto"
Width="Auto"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserReorderColumns="False" />
<DataGrid Grid.Row="1"
AutoGenerateColumns="False"
Width="1000"
Margin="0,73,0,10"
Name="heatMap"
IsReadOnly="True"
CanUserReorderColumns="False"
CanUserSortColumns="False"
ItemsSource="{Binding HeatMapCollection}"
Background="AliceBlue" />
</Grid>
</ScrollViewer>