I observed this problem in Grids and StackPanels , it can be applied to other panels, consider the following Xamls:
<Grid MaxWidth="200"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <Label>Title:</Label> <TextBox Grid.Column="1" Text="{Binding Title, UpdateSourceTrigger=PropertyChanged}"/> </Grid>
and
<StackPanel MaxWidth="200"> <Label>Title:</Label> <TextBox Text="{Binding Title, UpdateSourceTrigger=PropertyChanged}"/> </StackPanel>
(Edit: I have several such variable blocks, so I do not set the MaxWidth the TextBox itself)
Of course, I want the TextBox not increase when entering text, if the parent MaxWidth reached, this, however, does not happen, the panel changes until it reaches MaxWidth and the TextBox shoots outside.
If the second column of the grid has no width (by default, one star), then the TextBox will not grow, because it just takes up all the free space, so the text scrolls as if I also want, but this panel is an element in the ToolBar , and if the ToolBar is in horizontal ToolBarTray , this parameter causes instant overflow.
Any ideas on how to get the TextBox not to go beyond?
Edit:. The answers (maybe) work in normal scenarios, but the ToolBar somehow twists my layout, because, firstly, my controls always fall into the ToolBar overflow area for any reason and contents that were previously stretched inside the grid, more doesn't do that. Since my initial question was how to prevent this internal overflow (and not how to deal with the features of the ToolBar), I will just leave it at that.