Thursday, September 23, 2010

C# WPF Grid System

There are multiple "root" elements that you can use when designing a WPF application.

I want to talk about the "Grid" element.

This is pretty useful when you have a 'template' layout.  When you know where UI elements are going to be, and/or you are sure that your screen will be resized, you can use the 'Grid' element as your root.

The Grid element is very similar to the Table element in HTML.

A specific question I came across, was "Can I make one row a fixed size, while the other rows grow as the user changes the size of the form?".  This was an issue, because as the user changes the size of the form, the Grid cells, grow and shrink with the form.

Yes, you can set a specific row's height or a column's width.

There are 3 different ways you can set the height of a row.

row.Height = new GridLength(...

The three choices are:

    Pixel - fixed.  The value entered will be the amount of pixels exactly.
    Auto - this will make the row the size needed by the content.
    Star - takes as much as needed, or the amount in percent.

Just thought this was interesting.

Friday, September 3, 2010

CorFlags, C# and InteropServices.COMException (0x80040154): Class not registered

CorFlags is a Visual Studio command line utility that allows an executable that was compiled as (for instance) 'anycpu' to be run on a machine of a different architecture.

Some applications written in VS and compiled with x86, will not run on Windows 7.

The executable needs to be modified using corflags.

The error that caused me to find this issue is

System.Runtime.InteropServices.COMException (0x80040154): Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))

Run this in the VS command line.  Navigate to the executable folder.

corflags [path] /32bit

Now, the /32bit tells the .net framework to run this app as a 32 bit application.  Other options are available.

Thursday, September 2, 2010

No applicable name scope exists to resolve the name, Error. C# WPF

This error can occur when:

      A storyboard begins ->  myStoryBoard.Begin(myElement); <- and a programatically created element has not been added to a parent yet.

Add 'myElement' to a parent on the form.