I think what you want is not easy. ViewBox informs its subsidiaries that they have an inifite space in the layout bandwidth. After that, the display is inserted into the viewing window. Now the text field, which is ordered to infinite space, clearly can not be stretched. I have 2 solutions which, I think, are not what you want, but can be useful anyway.
First:
<Viewbox Grid.Column="1" Grid.Row="0" Stretch="Uniform" > <Grid Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Viewbox}}, Path=ActualWidth}"> <TextBox TextWrapping="Wrap" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> </Grid> </Viewbox>
this will stretch the infact text box, but disable the behavior expected from the viewport. What for? We told the ViewBox to keep the aspect ratio and set the text box to fill the entire width of the viewport, which preserves the size of the text box.
The second:
it would be to add height to the grid taken from the label, modified using the scaling formula of its viewport.
I have not tried this one yet, but it will include a value converter.
In conclusion: there is no easy way to achieve what you want, due to the way the viewbox arranges its children. If you just want to stretch horizontally, my first solution works great if you want to scale. I think you should do it yourself.
source share