Yoda
Yoda

Reputation: 18068

Define Column Width as a rest of unused pixels

I would like to define two columns. Second one 1280px wide and the first one the rest of unused pixels. How to do it?

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="1*" />
            <RowDefinition Height="9*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="REST OF THE WIDHT" />
            <ColumnDefinition Width="1280" />
        </Grid.ColumnDefinitions>
</Grid>

Upvotes: 0

Views: 185

Answers (2)

JBrooks
JBrooks

Reputation: 10013

Are you sure you want hard coded widths? Resize your browser while running it and see how it looks. If you use "Auto" for one column or row and then "1*" for the other, it will fill the "Auto" with what is needed and then the rest goes to the second one.

I would think this might work better for you:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="1*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="1*" />
    </Grid.ColumnDefinitions>
</Grid>

Then you start to make use of ScrollViewers for the content that might be bigger than its container.

Upvotes: 1

Matt
Matt

Reputation: 2682

You were on to the right idea with your RowDefinition

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="1*" />
        <RowDefinition Height="9*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="1280" />
    </Grid.ColumnDefinitions>
</Grid>

Star sizing basically tells the layout engine how you would like to divide up the space available to the parent element amount the children, in terms of proportions.

Here are a couple articles that may help:

Star Sizing

WPF Tutorial

Upvotes: 1

Related Questions