Laying out an App Page – Part 1
After knowing more about the controls, when to use them, and how to add them to the App UI, Now I’ll go deeper in how to arrange them inside the app page and build a consistent UI that is flexible for different screen resolutions. First thing to know is that there’re types of layout settings parameters for the UI controls:
- General parameters for any containing control: Alignment and Margin.
- Special parameters for some containing controls: such as: Row, RowSpan for the Grid control.
- Parameters for the controls itself: such as: Padding, FlowDirection
Let’s start with the first one:
1. General parameters for any containing control:
- Alignment: there’s ways for aligning a control inside its containing control
- Horizontal: whether you can align the control to the left, center, right, or stretching it horizontally over the containing control (Horizontal Stretching works when you give the control’s width and “Auto” value).
- Vertical: whether you can align the control to the top, center, bottom, or stretching it vertically over the containing control (Vertical Stretching works when you give the control’s height an “Auto” value).
- Margin: Setting the space that would be free around the control from the 4 directions.
So now, let’s try using those two parameters. Here’re two samples:
1. Centralizing a button inside a grid with no Margin setting
2. Stretch a button and giving it a 120px margin from the left, 40px from the top and the bottom, and 80px from the right:
Now let’s jump to the next type of parameters.
2. Special parameters for some containing control:
- Grid: The Grid controls is considered as one of the most important UI controls here as it features dividing it into rows and columns which allows building a flexible layout that works on different screen resolutions. Let’s see how we can implement this:
We can give the row or the column a value out of 3 types:
- Pixels: when we want the row or the column take an actual number of pixels in any screen resolution.
- Star: when we want to distribute the available (non-taken) space of a grid by weighted proportions.
- Auto: When we need the row or the column fit their content even if the content size is matter to change.Let’s practice now these types:I’ll create a layout where there’re:
- 120px free space from the left.
- 200×200 rectangle that is centralized vertically.
- Two rectangles, one of them is 2x bigger than the other and each one have 20px left margin and 200px top and bottom margin
Steps:
1. Let’s define the columns needed by clicking on the upper side of the grid when the orange line appears. Here, we will need 4 columns so, we’ll add 3 column definitions and give the 4 columns resulted the following values from the pop up that appears when we hover above any column and choose the value from the drop-down list that appears by clicking the small arrow:
- 1st column: 120 and choose the value by pixels.
- 2nd column: let’s choose the value by “Auto”. It’ll seem to be empty, that’s normal so don’t panic.
- 3rd column: let’s give it 1 and the value is by Star.
- 4th column: give it 2 and the value by Star to be 2x bigger than the 3rd column.
2. Now, let’s add the controls and layout them:
- Let’s add a rectangle, give it 200×200 width and height. And set the column by 1 to lay it in the 2nd column that we set before by Auto, then set its vertical alignment to center. Now we will mention that the hidden column appears and takes 200px size. Try to change the size of its content by changing the width of the rectangle or giving it left or right margins.
- Add a rectangle, set its width and height to Auto, lay it out in the 2nd column, stretch it vertically and horizontally, then give it the following margins: 20px left, 200px top and bottom
- Finally, add the last rectangle, set its width and height to auto, lay it out in the 3rd column, stretch it vertically and horizontally, and give it the same margins of the previous rectangle.
Now let’s run and see the output layout:
That’s for now. In the next post I’ll continue talking starting from the StackPanel control parameters so, stay tuned and keep practicing and if you have any question or any feedback that will be more than welcomed. Don’t hesitate to drop me an e-mail: ab.alnady@hotmail.com