is there a possibility to prevent a textblock from resize it's parent? I have a textblock with a lot of text and I want it to wrap, but not to enlarge the parents size. The size of the parent may be variable. Greetings Thomas
It is mostly used with textarea and div elements. To disable resizable property of an element use resize to none. It is the default value.
Method 1 (Using Overflow Property): We can use the overflow property of CSS to prevent the parents from collapsing. Set the value of the overflow property as “auto” for the parent and it will not collapse any more.
The resize property defines if (and how) an element is resizable by the user. Note: The resize property does not apply to inline elements or to block elements where overflow="visible". So, make sure that overflow is set to "scroll", "auto", or "hidden".
Unfortunately there is no Property for this feature.
The only workaround that I'm aware of is to either use an existing control or place another hidden control in the same space and then bind Width
of your TextBlock/TextBox
to the ActualWidth
of that control.
Here is an example when the TextBlock
doesn't effect the Width
of the ColumnDefinition
but it will get wider if the ColumnDefinition
is resized for another reason
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="1"
TextWrapping="Wrap"
Text="{Binding ...}"
Width="{Binding ElementName=sizingControl, Path=ActualWidth}"/>
<Rectangle Name="sizingControl" Grid.Column="1" Visibility="Hidden" />
</Grid>
For this to work, you need to set a width on the parent or place another grid or some container inside the parent which holds the textblock. Then set a width on that. The textblock will not wrap on a flexible parent.
Or better yet, just set a width on the textblock.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With