views:

201

answers:

1

I have the following setup on my WPF UserControl:

<GroupBox>
  <Grid>
    ...
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />

<GroupBox>
  <Grid>
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="..." />

I'd like the second ColumnDefinition to be the same width as the first ColumnDefinition, but I don't want to set an explicit width. Instead, I want both grids columns to automatically stretch to the width of the longest piece of content in either grid column!

Is this possible?

+2  A: 

It is possible by using SharedSizeGroup. Also check out IsSharedSizeScope.

<GroupBox>
  <Grid>
    ...
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" SharedSizeGroup="A" />

<GroupBox>
  <Grid>
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition SharedSizeGroup="A" />

See here for more information.

Lars Truijens
Great, just what I was looking for, thanks!
devdigital