When you have an element inside a grid the following properties control how the element is positioned and sized on the scene:
Thats a lot of properties affecting the size and position of the object! Blend tries to make it easier for you by auto setting some of these properties. However if you don't like what Blend sets it is still possible for you to manually override each of these properties. The purpose of this post is to explain our algorithm so that you know what properties are auto set and how and also to get feed back on how to improve this algorithm.
This post is primarily directed at elements whose parent layout container is a grid. For novices WPF provides a lot of panels like grid, canvas, stack panel etc. By default when you create a project in Blend the root panel(which is named LayoutRoot) is a grid. Inside this grid you place any elements that you like.
Before we dig deep into how Blend auto sets the above properties for you let us take a quick look at how each of the above properties on an element affect it:
Now let us turn our attention to blend and see how it auto sets the above properties. There are 2 important ways of creating any element in Blend. The first way is you select the element in the tool bar(say you select the rectangle tool) and draw out the rectangle on the art board. The other way is double click on the tool(say rectangle) and a rectangle is inserted for you on the scene. Each of these ways sets different properties.
In this post let us concentrate only on what happens if you draw out the element. When you draw out an element the properties set depend upon where you draw the element. Let us say you have a grid as the parent element. Now if you draw out a rectangle that fits completely with in the top half(left half) of the grid then the rectangle created has the following properties:
The same applies in reverse to element that completely fits the bottom(right) half of the grid.
If the rectangle spans the midpoint of the grid in height(or width) then the following properties are set on the rectangle:
Note by drawing out an element in the art board in Blend it is not possible to create a center aligned element.
In the next post I will explain what layout properties are set when you create an element by double clicking.