Parent Resize Prevention

is it possible to prevent the parent from resizing the text block? I have a text block with a lot of text, and I want to wrap it, but not increase the size of my parents. Parent size can be variable. Greetings Thomas

+4
source share
2 answers

Unfortunately, there is no property for this function.

The only workaround I know is to either use an existing control, or place another hidden control in the same space, and then bind the Width your TextBlock/TextBox to the ActualWidth that control.

Here is an example where TextBlock does not affect Width for ColumnDefinition , but it will expand if 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> 
+6
source

To do this, you need to set the width of the parent or place another grid or some container inside the parent that contains the text block. Then set the width for this. The text block will not be migrated to the flexible parent.

Or better yet, just set the width in the text block.

-1
source

All Articles