How do I constrain a container's height to the height of a specific content element?
Posted
by Robert Rossney
on Stack Overflow
See other posts from Stack Overflow
or by Robert Rossney
Published on 2010-06-11T23:21:42Z
Indexed on
2010/06/11
23:33 UTC
Read the original article
Hit count: 166
I'm trying to do something which seems like it should be extremely simple and yet I can't see how. I have a very simple layout, a TextBox with an image next to it, similar to the way it might look adorned with an ErrorProvider in a WinForms application. The problem is, I want the image to be no higher than the TextBox it's next to. If I lay it out like this, say:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Row="0" Grid.Column="0" MinWidth="100"/>
<Image Grid.Row="0" Grid.Column="1" Source="error.png" />
</Grid>
the row will size to the height of the image if the image is taller than the TextBox. This also happens if I use a DockPanel or StackPanel.
The naive solution would be to bind the Height
to the TextBox
's ActualHeight
. I'm sure this is wrong. But what's right?
© Stack Overflow or respective owner