Replies: 2 comments 2 replies
|
I think you are missing You generally don't layout a TextBox by itself though, it would be nested in a parent layout control like a Grid or StackPanel. So what you would normally do is have something like: <Grid RowDefinitions="Auto,Auto,Auto" MaxWidth="300" HorizontalAlignment="Stretch">
<TextBox Grid.Row="0" HorizontalAlignment="Stretch" />
<TextBox Grid.Row="1" HorizontalAlignment="Stretch" />
<TextBox Grid.Row="2" HorizontalAlignment="Stretch" />
</Grid> |
|
Your follow-up describes a measure-pass preference, so For an initial size-to-content dialog whose fields should request a stable width but still stretch later, your decorator approach is a reasonable reusable solution. Keep the distinction explicit:
Avalonia's layout documentation describes that measure/arrange split, and the stock Decorator already supplies the child-arrangement plumbing. If you add a configurable preferred-width styled property, make changes to it invalidate measure. That preserves the semantics you want without subclassing every input control. It is still a custom layout policy, not a built-in JavaFX-style |
Uh oh!
There was an error while loading. Please reload this page.
I come from JavaFX, which has the concept of a "preferred size" that can be used to override a control's desired size. For example, a TextBox could have a preferred width of 300 px. The parent is still free to resize the control within its min/max width constraints if necessary. Avalonia does not seem to have such a property.
JavaFX:
So far i only found two ways to add/enforce a preferred size:
Maybe I'm missing something simpler to achieve the same effect?
All reactions