问题描述
我只是想知道如何让用户在运行时通过在 WPF 中拖动它的角来调整 TextBox 控件的大小.不太重要的是,调整所有控件的大小是否使用相同的技术?
Was just wondering how I would go about letting the user resize a TextBox control at runtime by dragging its corners in WPF. Less importantly, is the same technique used for the resizing of all controls?
谢谢你:)
推荐答案
您应该尝试将文本框的对齐方式设置为拉伸并将其放置在可以调整大小的容器中,例如带有 gridsplitters 的网格(或在可调整大小的窗口中).这比尝试创建自定义的可调整大小的文本框要容易得多,并且它会更好地与您的布局的其余部分配合使用.
You should try setting the textbox's alignments to stretch and placing it inside a container that you can resize, like a grid with gridsplitters (or in a resizeable window). It's much easier than trying to create a custom resizeable textbox, and it will work better with the rest of your layout.
下面是一个真实应用的示例:
Here's an example from a real app:
<Grid>...
<GridSplitter Grid.Row="1" Grid.ColumnSpan="2" ResizeDirection="Rows" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Height="4" BorderThickness="0,0,0,1" BorderBrush="Gray" Background="Transparent"/>
<TextBox Grid.Row="2" Grid.Column="0" Margin="6,6,6,6" Name="RequestTextBox" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap" Text="{Binding Request, Mode=TwoWay}"/>
<GridSplitter Grid.Row="2" Grid.ColumnSpan="2" ResizeDirection="Rows" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Height="4" BorderThickness="0,0,0,1" BorderBrush="Gray" Background="Transparent"/>
...</Grid>
这篇关于在 WPF 中运行时调整文本框的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!