对齐按钮内容

30

我希望WPF按钮的内容左对齐,但是尝试了以下代码后,文字仍然在按钮中心。

    <Button >
        <StackPanel HorizontalAlignment="Stretch">
            <TextBlock HorizontalAlignment="Left" Text="Save"/>
        </StackPanel>
    </Button>

我该怎么做?

3个回答

71

17

您不需要StackPanel或TextBlock。您只需要

<Button HorizontalContentAlignment="Left" Content="Save" />

1
我的实际实现内容有两个元素,而我的示例中没有。 - Jose

5

您可以水平和垂直对齐

<Button Content="Export" VerticalContentAlignment="Bottom" name="MyBtn1"  />

或者

<Button Content="Export" HorizontalContentAlignment="Center" name="MyBtn2"  />

请查看下面的图片以查看可能的设置:

enter image description here

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接