0

我在扩展器中有一个数据网格,而 gatagrid 有 10 多列。然后
应该滚动扩展器中的数据网格。但它不能滚动查看其他列。我的代码如下。

                <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>
4

1 回答 1

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 甚至不应该是必需的。

于 2012-10-18T09:59:26.920 回答