我在中有3个控件,Grid.Row
但是如何使它们使用页面的整个宽度?
这是我的xaml:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="140" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0"
Grid.Row="1"
Source="/Assets/image1.png"
Height="25"
Width="25" />
<TextBox Grid.Column="1"
Margin="10,0,0,0"
Text="{Binding InputText, Mode=TwoWay}"
BorderBrush="Black"
BorderThickness="2"
VerticalAlignment="Center">
</TextBox>
<Button Grid.Column="2"
BorderThickness="2"
HorizontalAlignment="Right"
Command="{Binding AddTextCommand}"
Margin="10,0,0,0">
<TextBlock x:Uid="ButtonText" />
</Button>
</Grid>
现在是结果:
如您所见,它是左对齐的,我该如何使用它的整个宽度?
你的代码只显示了3点控制(Image
,TextBox
,Button
),而您的截图给出了4所控制。我想上面的全角控件丢失了,但这没问题。
如果我们分解您的XAML,您将:
在您放置的按钮上HorizontalAlignment="Right"
(默认为“左”),您在其中说:仅使用必要的空间并将控件放在右侧。如果要使用可用的完整宽度,则必须使用HorizontalAlignment="Stretch"
。
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="140" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0"
Source="/Assets/image1.png"
Height="25"
Width="25" />
<TextBox Grid.Column="1"
Margin="10,0,0,0"
Text="{Binding InputText, Mode=TwoWay}"
BorderBrush="Black"
BorderThickness="2"
VerticalAlignment="Center">
</TextBox>
<Button Grid.Column="2" x:Uid="ButtonText"
BorderThickness="2"
HorizontalAlignment="Stretch"
Command="{Binding AddTextCommand}"
Margin="10,0,0,0" />
</Grid>
请注意,我也去掉了TextBlock
从Button
与移动x:Uid
标签按钮。只需ButtonText.Content
在您的资源中使用即可将按钮本地化,而无需在其中放置按钮TextBlock
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句