本文介绍了将HorizontalAlignment设置为Stretch和Left的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
注意:我阅读了此问题及其答案:。
仅适用于网格。这是更新的xaml:
< Grid ShowGridLines = True x:Name = _ testGrid Height = 30 >
< Grid.ColumnDefinitions>
< ColumnDefinition MaxWidth = 75 Width = * />
< ColumnDefinition Width = 0.01 * />
< ColumnDefinition MaxWidth = 130 Width = * />
< ColumnDefinition Width = 0.01 * />
< ColumnDefinition MaxWidth = 100 Width = * />
< ColumnDefinition Width = 0.01 * />
< /Grid.ColumnDefinitions>
< TextBox Grid.Column = 0 Text = Text 1 Margin = 5 />
< TextBox Grid.Column = 2 Text = Text 2 Margin = 5 />
< TextBox Grid.Column = 4 Text = Text 3 Margin = 5 />
< / Grid>
Note: I read over this question and its answers: HorizontalAlignment=Stretch, MaxWidth, and Left aligned at the same time?. None of them do what I am looking for.
I have the following xaml:
<Grid ShowGridLines="True" x:Name="_testGrid" Height="30" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBox Text="Text 1" HorizontalAlignment="Stretch"
MaxWidth="75" Margin="5"/>
<TextBox Grid.Column="1" Text="Text 2" Margin="5"
HorizontalAlignment="Stretch" MaxWidth="130"/>
<TextBox Grid.Column="2" Text="Text 3" Margin="5"
HorizontalAlignment="Stretch" MaxWidth="100"/>
</Grid>
It produces this:
This setup has great resizing support. If the window shrinks then the TextBoxes will shrink too.
The only problem is I need them left aligned:
All the solutions I see end up chopping off part of the textbox (not shrinking it).
Is what I am looking for possible with WPF?
解决方案
Found an answer here.
It works only with a grid. Here is the updated xaml:
<Grid ShowGridLines="True" x:Name="_testGrid" Height="30" >
<Grid.ColumnDefinitions>
<ColumnDefinition MaxWidth="75" Width="*"/>
<ColumnDefinition Width="0.01*" />
<ColumnDefinition MaxWidth="130" Width="*"/>
<ColumnDefinition Width="0.01*" />
<ColumnDefinition MaxWidth="100" Width="*"/>
<ColumnDefinition Width="0.01*" />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Text="Text 1" Margin="5"/>
<TextBox Grid.Column="2" Text="Text 2" Margin="5" />
<TextBox Grid.Column="4" Text="Text 3" Margin="5" />
</Grid>
这篇关于将HorizontalAlignment设置为Stretch和Left的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!