Q:

Prevent a control in a grid to change its column width

I can't figure out how to manage properly the width of a grid column with a user control in one of its cell. I have this xaml for a window:
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="auto" />
        <RowDefinition Height="auto" />
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="auto" />
    </Grid.ColumnDefinitions>        
    <Button Grid.Row="0" Content="Button" Width="100" HorizontalAlignment="Left"/>
    <TextBox Grid.Row="1" />
    <local:UserControl1 Grid.Row="2"
                        HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Grid>

and the user control is a drawing set to stretch as needed:
<UserControl x:Class="WpfApplication1.UserControl1"
             Height="auto" Width="auto">

    <Grid Background="Aqua">
        <Path Fill="Coral" Stroke="Black" StrokeThickness="1"
              Stretch="Uniform"
              HorizontalAlignment="Left" VerticalAlignment="Top">
            <Path.Data>
                <RectangleGeometry Rect="40,20, 140,30" RadiusX="10" RadiusY="10" />
            </Path.Data>
        </Path>
    </Grid>
</UserControl>

To help I have set the user control background in blue.
I would like to have the width of the column ignoring the "natural" size of the user control. I mean I would like the user control to not determine the width during the layout of the column, but to adjust its width to whatever is the width of the column.
In the example, initially the Grid would set the column width to the value of the button, and the user control would use the column width to resize itself. Then if a long text is entered in the Textbox, as soon as the Textbox starts to be wider than the button, and the column starts to be resized as well, in turn the user control would adjust to maintain the same size than the column.
I've tried combinations of stretch values, and also have used MeasureOverride() in the user control. The latter doesn't work because the AvalaibleSize received is Infinity, not the column width.

A:

I was able to achieve what (I believe) you're looking for by giving the TextBox a name, and binding the width of the UserControl to the ActualWidth of the TextBox.  Here's the code for the Window's Grid:
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="auto" />
        <RowDefinition Height="auto" />
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="auto" />
    </Grid.ColumnDefinitions>
    <Button Grid.Row="0" Content="Button" Width="100" HorizontalAlignment="Left"/>
    <TextBox Grid.Row="1" x:Name="entryTextBox" />
    <local:UserControl1 Grid.Row="2"
                        Width="{Binding ElementName=entryTextBox, Path=ActualWidth}"
                        HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Grid>

Hope that helps!

A:

Old question, so it will probably not help OP anymore, but it may help others:
Put UserControl1 inside a Canvas. Then bind the Width to the ActualWidth of the parent Grid.
Example:
<Grid Name="mainGrid">
          <Grid.RowDefinitions>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
          </Grid.RowDefinitions>
          <Something Grid.Row="0"/>
          <Canvas Grid.Row="1">
                <MyControl Width="{Binding ActualWidth, ElementName=mainGrid, Mode=OneWay}"/>
          </Canvas>
</Grid>

The canvas will take the available width, but will never ask Grid for more.
The controls inside the canvas get no size from Canvas, so you must give it a size manually. In this case, we want to give it the size of the parent Grid.

