Z
Z
zmeyloki2015-11-13 11:48:59
WPF
zmeyloki, 2015-11-13 11:48:59

How to change the number of cells in a Grid on orientation change?

Good afternoon. Not so long ago I began to study this topic, so the question is rather banal. There is an unfinished application for Windows Phone, a calculator. What is the essence of the problem, in portrait orientation it looks quite nice, but in landscape ... To put it mildly, not very much.
0b4be7a42ec747e7890d53e794182614.png
As I want to fix the situation, when changing to landscape orientation, it seems to me that it is worth reducing the width of the buttons and the font, adding several cells with buttons, like tan, sin, cos, root, square, etc. Actually, the question itself: "How can I do what I have planned?"
This is done using styles or programmatically using functions:

public MainPage()
        {
            InitializeComponent();
            this.OrientationChanged +=
                new EventHandler<OrientationChangedEventArgs>(MainPage_OrientationChange);
        }
        void MainPage_OrientationChange (object sender,OrientationChangedEventArgs e)
        {
            if ((e.Orientation == PageOrientation.LandscapeRight)||(e.Orientation == PageOrientation.LandscapeLeft))
            {
                
            }
            else if ((e.Orientation == PageOrientation.PortraitDown)||(e.Orientation == PageOrientation.PortraitUp))
            {
                
            }
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Zolotov, 2015-11-13
@zmeyloki

I see two problems:
1. You have hard-coded cell and/or text block sizes. You need to set the height for the row and the width for the column to Auto for the grid, do not specify sizes for the text block.
2. The Streth property is not specified for the picture (I can make a mistake in spelling), so it doesn’t scale correctly for you.
In general, when you change the screen orientation, adding other buttons is not entirely correct, but you can add cells that will be behind the screen in portrait orientation. In landscape mode, they will seem automatic.
PS. Code in page classes is evil, look towards MVVM

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question