Patrik
Patrik

Reputation: 1336

How to easily change the layout of the screen from Portrait to Landscape and vice versa in WPF

Let's suppose we have the designed the layout of some WPF application to be used on standard Full HD screen 1920x1080. Then we need to rotate the screen and install it in a box that is mounted on kiosk PC but in Portrait orientation.

I need to find a way on how to rotate the screen easily or at least in some more elegant way.

I tried to use use RenderTransform and RotateTransform applied to the contents of the window but this rotates the image and of course not the layout.

The controls remain of the same width and height.

Is there a way to do it automatically or should I take each control and change it properties one by one ?

The problem is present for TextBlocks and TextBoxes. They are intended to be used horizontally. You can rotate it but the layout is calculated based to it's horizontal width.

BTW. Rotation of the entire window is not allowed. It throws an exception.

Upvotes: 0

Views: 650

Answers (1)

Patrik
Patrik

Reputation: 1336

It looks like that I have found the solution myself. If we choose the Layout transform instead of RenderTransform then the visual system does the arrangement and measurement of the layout automatically before the rendering.

The WPF framework does the job in this order

LayoutTransform Measure Arrange RenderTransform Render

This is best described here LAYOUTTRANSFORM VS. RENDERTRANSFORM - WHAT'S THE DIFFERENCE?

Upvotes: 1

Related Questions