Sandeep Bansal
Sandeep Bansal

Reputation: 6394

Align Labels in Grid WPF

I'm having an alignment issue, I'm trying to position the labels from start to end but they're starting in the middle. Can someone shed some light on what I need to do to change it and get it aligned how I want.

enter image description here

        <Grid Height="23.3" Margin="169,0,8,8.199" VerticalAlignment="Bottom" Width="Auto">
<Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
            <Rectangle Grid.ColumnSpan="6" Fill="#FFDDDDDD" Stroke="#FFD7D7D7" RadiusX="2" RadiusY="2"/>


            <Label Grid.Column="1" Grid.Row="1" x:Name="lblAbout" Content="{Binding Source={StaticResource localisation}, Mode=OneWay, Path=.[Language.about]}" HorizontalAlignment="Left" Foreground="#FF585858" FontSize="10" Cursor="Hand" d:LayoutOverrides="Height" MouseLeftButtonUp="lblAbout_MouseLeftButtonUp"/>
            <Label Grid.Column="2" Grid.Row="1" Content="{Binding Source={StaticResource localisation}, Mode=OneWay, Path=.[Language.settings]}" HorizontalAlignment="Left" Foreground="#FF585858" FontSize="10" Cursor="Hand" d:LayoutOverrides="Height"/>
            <Label Grid.Column="3" Grid.Row="1" Content="{Binding Source={StaticResource localisation}, Mode=OneWay, Path=.[Language.feedback]}" Foreground="#FF585858" FontSize="10" Cursor="Hand" HorizontalAlignment="Left" Width="Auto" d:LayoutOverrides="Height"/>
            <Label Grid.Column="4" Grid.Row="1" Content="{Binding Source={StaticResource localisation}, Mode=OneWay, Path=.[Language.help]}" Foreground="#FF585858" FontSize="10" Cursor="Hand" HorizontalAlignment="Left" Width="Auto" d:LayoutOverrides="Height"/>
            <Label Grid.Column="1" Grid.Row="1" Content="{Binding Source={StaticResource localisation}, Mode=OneWay, Path=.[Language.checkingUpdates]}" Foreground="#FF585858" FontSize="10" Cursor="Hand" d:LayoutOverrides="Height" Visibility="Collapsed"/>
        </Grid>

Upvotes: 2

Views: 4927

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564811

Right now, since all of your columns are using star sizing, they will all be even sized and stretched across the width.

I believe you want:

<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />

This will cause them to stack left to right, and "fill" at the end.

Upvotes: 3

Related Questions