Dmitrii Polianskii
Dmitrii Polianskii

Reputation: 575

Wpf alignment button

I think I can create shred size of grid but I'm not sure. Could you help me please. How can I do it?

Upvotes: 0

Views: 41

Answers (1)

Sinatr
Sinatr

Reputation: 21969

You can utilize Grid columns to automatically center your content (a is unknown) like this:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>

    <!-- content in the middle -->
    <Grid Grid.Column="1"> ... </Grid>
</Grid>

If your intents are to ensure what a is the minimum necessary width (left and right content should have same width), then it's opposite:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" SharedSizeGroup="a" />
        <ColumnDefinition />
        <ColumnDefinition Width="Auto" SharedSizeGroup="a" />
    </Grid.ColumnDefinitions>

    <!-- left content -->
    <Grid> ... </Grid>
    <!-- right content -->
    <Grid Grid.Column="2"> ... </Grid>
</Grid>

Upvotes: 3

Related Questions