[英]C# WPF XAML multiple auto width or height
For example: 例如:
<TextBox x:Name="TextBox1" Text="A text" Width="Auto"/>
Instead of setting the width as Auto , I want to set it as 2*Auto , how to achieve it in XAML directly? 我不想将宽度设置为Auto ,而是将其设置为2 * Auto ,如何直接在XAML中实现它?
How about setting it through column definitions of your grid? 如何通过网格的列定义进行设置? Then set HorizontalAlignment="Stretch" of your TextBox
然后设置TextBox的HorizontalAlignment =“ Stretch”
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" x:Name="TextBox1" Text="A text" Height="50" VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
</Grid>
I'm not quite sure what your aim is here. 我不太确定您的目标是什么。 Usually you let a container around the text box take care of that for you.
通常,您可以让文本框周围的容器为您解决这个问题。 One (hacky) way might be to use a grid with HorizontalContentAlignment=Stretch, and place a second TextBox in there with the text doubled and Visibility=Hidden.
一种(骇人听闻的)方法可能是使用HorizontalContentAlignment = Stretch的网格,然后在其中放置第二个TextBox,其中文本加倍并且Visibility = Hidden。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.