UWP按钮拉伸并左对齐

时间:2016-10-12 10:28:07

标签: xaml

您好如何制作此按钮:

                        <Button x:Name="StartButton" Background="Transparent" Click="StartButton_Click">
                        <Button.Content>
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                                <TextBlock FontSize="18" FontFamily="Segoe MDL2 Assets" Text="&#xE768; " VerticalAlignment="Center"/>
                                <TextBlock FontSize="18" Text="Start"/>
                            </StackPanel>
                        </Button.Content>
                    </Button>

填充其父级(水平)并将其内容对齐?

2 个答案:

答案 0 :(得分:1)

这就是答案:

<Button x:Name="StartButton" Background="Transparent" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left">
    <TextBlock FontSize="18">
        <Run FontFamily="Segoe MDL2 Assets" Text="&#xE768; "/>
        <Run Text="Start"/>
    </TextBlock>
</Button>

答案 1 :(得分:0)

为了获得预期的结果,我建议您使用<Run>来定义TextBlock

的内联

这应该是:

<Button x:Name="StartButton" Background="Transparent" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Click="StartButton_Click">
    <TextBlock FontSize="18" HorizontalAlignment="Left">
        <Run FontFamily="Segoe MDL2 Assets" Text="&#xE768; "/>
        <Run Text="Start"/>
    </TextBlock>
</Button>