开发者

DataGrid column re-sizing, re-sizes Grid ColumnDefinitions

开发者 https://www.devze.com 2023-03-22 18:09 出处:网络
When re-sizing a column in a DataGrid(or any other control that has columns) that has a ColumnSpan spanning a ColumnDefinition with Width=\"*\" while being nested inside a ScrollViewer, there will be

When re-sizing a column in a DataGrid(or any other control that has columns) that has a ColumnSpan spanning a ColumnDefinition with Width="*" while being nested inside a ScrollViewer, there will be this weird behavior where the ColumnDefinitions will re-size as well.

Below XAML example shows this behavior.

Does anyone know what is happening here and why it is happening? The ColumnDefinitions even have fixed Widths, but still they are re-sizing...

<Window.Resources>
    <x:Array x:Key="PointList" Type="{x:Type Point}">
        <Point X="1" Y="4" />
        <Point X="2" Y="3" />
        <Point X="3" Y="2" />
        <Point X="4" Y="1" />
    </x:Array>
</Window.Resources>    

<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100" />
            <ColumnDefinition Width="200" />
            <ColumnDefinition Width="*" />
        </Grid.Column开发者_JAVA技巧Definitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Label Background="Red" Grid.Column="0" Content="Something 1" />
        <Label Background="Green" Grid.Column="1" Content="Something 2" />
        <Label Background="Blue" Grid.Column="2" Content="Something 3" />

        <DataGrid ItemsSource="{StaticResource PointList}" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" />
    </Grid>
</ScrollViewer>


I would assume this happens because during measuring the ScrollViewer reports infinite space in both dimensions (with your scrollbar settings that is).

0

精彩评论

暂无评论...
验证码 换一张
取 消