Using SharedSizeGroup with ColumnSpan in a Wpf Grid

When I create a grid using both the SharedSizeGroup on the columns and the column control, the grid goes into a “psychic” motion and maximizes the processor core.

I am sure there must be a good reason why this does not work, but I can’t think about it! How else can I achieve this size layout?

<Grid IsSharedSizeScope="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" SharedSizeGroup="Columns"/>
            <ColumnDefinition Width="Auto" SharedSizeGroup="Columns"/>
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Label Grid.Column="0">Blah</Label>
        <Label Grid.Column="1">Blah Blah Blah Blah</Label>

        <Label Grid.Row="1" Grid.ColumnSpan="2">ajsgdeererajgsfdg dfg df gdfg djgsad</Label>
    </Grid>
+3
source share
1 answer

What you did essentially created infinite recursion in your layout.

  • To separate the size of the columns, you must first calculate their own size.
  • Then they can be synchronized on a larger basis (perhaps column 1 is here).
  • , 0 , 1,
  • 1 , 1 , .
  • 1 ( )

SharedSizeGroup , - , . , , - UniformGrid.

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <UniformGrid Rows="1" HorizontalAlignment="Left">
        <Label >Blah</Label>
        <Label >Blah Blah Blah Blah</Label>
    </UniformGrid>

    <Label Grid.Row="1">ajsgdeererajgsfdg dfg df gdfg djgsad</Label>
</Grid>
+4

Source: https://habr.com/ru/post/1789605/


All Articles