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






No problem, WPF or SL?

– Chris W.
Jan 11 '13 at 17:24






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

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ