Onelio
Onelio

Reputation: 323

Changing size of the frame and elements in UWP

I want to know if there is a way to resize the frame and the elements inside of it when the window size change. I always want to have the same proportion in the size of the elements inside the frame.

Example:

1- Windowsize = 100(in x) and Imagesize = 50(in x) locationx = 25

2- Windowsize = 50(in x) and Imagesize = 25(in x) location x = 12.5(~12)

In this case, the windowsize is "something", imagesize is 1/2 of "something" and locationx of the image is 1/4 of something. I wan't to do something like this but with every element inside the frame.

Thanks!

Upvotes: 0

Views: 1404

Answers (1)

AlexDrenea
AlexDrenea

Reputation: 8039

You can use the <ViewBox/> control which does exactly that.

<Page>...
<Grid>
    <ViewBox HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <StackPanel>
            <Button Content="test" HorizontalAlignment="Left"/>
            <TextBlock Text="some text"/>
        </StackPanel>
    </ViewBox>
</Grid>
</Page>

In the example below, the ViewBox is placed inside a Grid and stretched both Horizontally and Vertically which causes it to stretch with the Page resize.

Reference docs here.

Upvotes: 1

Related Questions