Tomas Aschan
Tomas Aschan

Reputation: 60664

Grid inside button won't stretch horizontally

Given the following markup, I would have expected the chevron to go all the way to the right of the button, but it doesn't - instead, the stack panel and the chevron are tight together in the middle of the button.

<Button Background="Teal" HorizontalAlignment="Stretch">
    <Grid HorizontalAlignment="Stretch">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"></ColumnDefinition>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <StackPanel HorizontalAlignment="Stretch"
                    Grid.Column="0">
            <TextBlock HorizontalAlignment="Center"
                       TextAlignment="Center"
                       FontSize="60">Click!</TextBlock>
            <TextBlock HorizontalAlignment="Stretch"
                       TextAlignment="Center"
                       FontSize="20">Cool things will happen</TextBlock>
        </StackPanel>
        <TextBlock Grid.Column="1"
                   FontSize="60"
                   FontFamily="Segoe UI Symbol">
            &#xe013; <!-- unicode for chevron right in this font -->
        </TextBlock>
    </Grid>
</Button>

Chevron should be all the way to the right

Upvotes: 1

Views: 1330

Answers (1)

Max
Max

Reputation: 1830

You can try to set the HorizontalContentAlignment of the button to Stretch.

Upvotes: 5

Related Questions