对齐按钮内容

时间:2009-06-02 20:18:30

标签: wpf controls templates wpf-controls

我希望wpf按钮的内容保持对齐 我尝试了以下内容,但文本仍然在按钮内居中。

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

我该怎么办?

3 个答案:

答案 0 :(得分:53)

找到它,它是HorizontalContentAlignment

:)

答案 1 :(得分:15)

您不需要StackPanel或TextBlock。你所需要的只是

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

答案 2 :(得分:5)

您可以双向对齐,水平和垂直

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

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

请参阅以下图片以查看可能性设置:

enter image description here

enter image description here