XAML TextBox: How to keep height fixed even though verticalalignment stretched?
XAML TextBox: How to keep height fixed even though verticalalignment stretched?
I implemented a custom control which simply contains a label and a textbox to enter multiline text:
<DockPanel Name="MyStackPanel" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" LastChildFill="True" >
<Label DockPanel.Dock="Top" Content="Binding MyTitle" Style="StaticResource PropertyNameLabelStyle" />
<TextBox DockPanel.Dock="Bottom" Text="Binding Path=MyText, Mode=TwoWay" IsReadOnly="Binding MyIsReadOnly" HorizontalAlignment="Stretch" AcceptsReturn="True" Margin="5,5,5,5" VerticalScrollBarVisibility="Visible" IsUndoEnabled="True" />
</DockPanel>
It is important that the TextBox fills all the space its parent has to offer but not more - which is working well with the code above. However if the user types more text than the displayed TextBox offers the TextBox rather becomes bigger (higher) then simply enabling the vertical ScrollBar, which is what I - and I guess most of all other programmers - want.
TextBox
TextBox
TextBox
ScrollBar
WPF! Are there differences?
– user1781720
Jan 11 '13 at 17:26
1 Answer
1
I am very new to XAML but I thought you might like to try this:
I set the VerticalAlignment for the TextBox itself:
VerticalAlignment
<TextBox Text="ABC" MinWidth="200" VerticalAlignment="Center">
</TextBox>
It worked for me.
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy
No problem, WPF or SL?
– Chris W.
Jan 11 '13 at 17:24