Sunday, 25 August 2013

The Grid: What it Means in a New WPF Application

Grids within Windows

When you wizard-up a new WPF application, and look at the MainWindow's XAML, you expectedly see a beginning and ending Window tag, which comes as no surprise given that the Window class is clearly fundamental to Window Creation.  Within these Window tags, you see Grid tags. Now this you might be less familiar with.

Now I will tell you some quick facts that you already know. The Grid class is part of System.Windows. Controls, and came about in .NET 3.0 and is also included in Silverlight. This is pretty much true for just about any of the early WPF Controls, so nothing deeply insightful about Grid just yet.

What Grids Actually Are

Now for the revelation. A Grid is a Panel (just like a StackPanel or any other Panel) that inherits from teh abstract class Panel (System.Windows.Controls.Panel to give it its fully-qualified form). Many of its properties come from earlier classes in the hierarchy. Unless you know the classes in the hierarchy well you will have a difficult job knowing what is unique to Grid, and what is just inherited members.

Positioning Controls in a Grid using Attributes

A Grid allows you to create Grid.RowDefinitions and Grid.ColumnDefinitions using RowDefinition and ColumnDefinition tags respectively.Then each control will have Grid.Row=X and Grid.Column=Y in their attribute chain.

No comments: