Michael Sandler
Michael Sandler

Reputation: 1309

Margin pushes element out of view when resizing

I have a Grid wherein I have positioned a number of elements. One of them is a Label which is centered 30 pixels from the top of the grid.

When the user resizes the Grid the Label remains 30 pixels from the top which is what I want... until the height of the Grid becomes less than 30 + label height and the Label begins to disappear at the bottom of the grid.

I would like the Label to stay 30 pixels from the top except when there is not enough space for the margin and the Label, whereupon I want the margin to shrink and allow the Label to remain in view as long as possible.

I have tried various permutations of RowDefinitions without success. Can it be done?

Upvotes: 0

Views: 73

Answers (1)

brunnerh
brunnerh

Reputation: 184376

You could do something like this if it is not too much of a clutter for the layout:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition MaxHeight="30"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Label Grid.Row="1" HorizontalAlignment="Center" Content="Lorem Ipsum"/>
</Grid>

Upvotes: 2

Related Questions