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.

All you wanted to know about WPF (and Silverlight) StackPanel..

StackPanel is a bit like a ToolBar that instead of going from left to right or right to left, goes top to bottom (in the default case). Although a StackPanel is actually more flexible..as it can also go from left to right, simply by setting the attribute Orientation="Horizontal". As common with WPF controls, this one has been around since .NET 3.0 and is also included in Silverlight. It inherits from System.Windows.Controls.Panel which inherits from System.Windows.FrameworkElement (from PresentationFramework.dll).  Interestingly, the same inheritance structure is true also for Silverlight! However, the dll in which is class is contained is quite different (System.Windows.dll).

What do you know about ToolBar programming in WPF?

The WPF ToolBar has been around since .NET 3.0. It contains buttons (often with images) that invoke commands.  A ToolBar is often located within a ToolBarTray. The ToolBar is given a Band, which is an integer that indicates its position within the ToolBarTray.

Saturday 24 August 2013

K32GetModuleInformation - could not be located in DLL KERNEL32.DLL

Happens on install of Visual Studio 2012 Express.

Wednesday 21 August 2013

The readonly keyword in C# (and its similarity to adjectives)

This keyword, or more precisely a modifier, is that acts as a piece of in-code documentation. The readonly keyword says the member variable is initialized only on first declaration or in the constructor; nothing else can set the variable. It does not offer performance gains.

The const keyword on the other hand indicates a variable can only be initialized at the point of declaration. It is thus more restrictive than the readonly modifier.

Note that in-code documentation in the form of modifiers generally have to be verifiable by the compiler at compile time; this is one of the unwritten design rules of C#.

A modifier is anything used to modify the declaration of types and type members. An example modifier on a class is the partial modifier. Access modifiers comprise private, public, internal and protected.

Static is a modifier we hardly even think about; we use it so often in coding. Modifiers are like adjectives (e.g. the "blue" boat, the "static" void method).