在以下的XAML中,按钮将会自动伸展以适应窗口的宽度,并且在调整窗口大小时也一样。然而,TextBlock和蓝色方框是居中对齐的。您该如何更改它呢?
1)TextBlock位于Button内部,但是与实际Button宽度左对齐(即在窗口左侧)
2)Canvas位于Button内部,但是与实际Button宽度右对齐(即在窗口右侧)
好像在这种情况下"HorizontalAlignment=Stretch"不起作用,而使用Auto sizing时,Button内部的Grid始终仅增长到其内容所需的最小宽度。
好像在这种情况下"HorizontalAlignment=Stretch"不起作用,而使用Auto sizing时,Button内部的Grid始终仅增长到其内容所需的最小宽度。
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Window"
Title="test"
Width="640" Height="480">
<Grid x:Name="LayoutRoot">
<Button Height="30">
<Grid HorizontalAlignment="Stretch">
<TextBlock Text="Sample Text" HorizontalAlignment="Stretch" TextAlignment="Left"></TextBlock>
<Canvas Width="40" Background="AliceBlue" HorizontalAlignment="Right"></Canvas>
</Grid>
</Button>
</Grid>
</Window>