Monday, February 26, 2007

New Blog at The Digital Lifestyle

Ian Dixon - the man behind The Media Center Show podcasts - has recruited me to be (one of?) the developer(s) writing for the Media Center Development blog at

Because the site is a little easier to use in terms of spell-checking and pasting code, I'm probably going to be spending a little more time at the new blog. To start with I'll mainly be re-posting nicely-edited versions of the posts I've already put here. New content won't take long though guys.

Check it out at

Monday, February 19, 2007

MCMLookalike Initial Release

The first release of MCMLookalike is done. I threw the project and installer together in around about 45 minues (not counting the 'controls.mcml' file), so I hope there are no GLARING errors in the code.

If you are an MCML developer, take a look. It's a basic program using a couple of simple pre-defined controls. It also includes a template installer you can use to distribute your program.

Tuesday, February 13, 2007

Installing Your Program - Part 2 - Installing Your Files

Step 2 of the install process is nice and easy - no command-prompt needed :)

Create a new project (add it to the existing solution) in Visual Studio. Under 'Other Projects', you'll find "Setup and Deployment". This will allow you to create an installer.

Give your program a name like <program name>Setup - try to steer clear of generic names like 'setup', simply because it's very easy to get your 'setup.msi' confused with hundreds of others with exactly the same name.

Now your new project should appear in the Solution Explorer. Click it, and go to the 'View' menu. Under 'View', you should now have the 'Editor' submenu. This allows you to choose to edit the various parts of your installation - the files, registry settings etc.

Choose 'File System', if it isn't selected already.

The first entry will read 'File System on Target Machine'. Right-click this line and a popup menu will appear. Choose 'Add Special Folder|Global Assembly Cache Folder' to add the GAC to your installer.

Right click on the new folder that will appear and choose 'Add|Project Output...' from the popup menu. You can then 'Primary Output' from the list of different types of file you can include from your project.

This will add your .NET classes into the Global Assembly Cache, as well as get a reference to a number of extra DLL's and modules that your application will require. If you check the solution explorer, you'll notice that Microsoft.MediaCenter.dll and a couple of it's friends will have appeared.

We don't need to install these, although they ARE required for your program to work correctly. To avoid installing these (which would be illegal), we right click on the files and choose 'Exclude'.

There! Your .NET files are now installing. The next thing we need to do is tell Media Center where our program is, what it does and what it's called. That's covered in the next post...

Installing Your Program - Part 1 - Signing Your Assembly.

This is the first part of my little review on writing an installer to get your MCML program into Media Center.

The code part of your Media Center program (usually written in C#) is installed into the Global Assembly Cache (GAC) of Windows. The GAC is used to store .NET assemblies that are shared across multiple programs. Your basic Windows forms classes etc. all live in the GAC.

Before any program can be added to the cache, it must be strongly named. A strongly named assembly has a public and private key associated with it, to ensure that it is actually the original class and not a modified or doctored version.

To generate this key, you will need to use the 'SN' command that ships with Visual Studio. You will find it in <Visual Studio Install Directory>/SDK/v2.0/BIN

Use 'cmd' (the command-line interpreter) or even better, open the command prompt from the start menu, under 'Programs|Visual Studio 2005' so you won't need to bother with your path information.

Type 'sn -k <filename>.snk' to generate a new key file.

Then in Visual Studio, right click on your project in the project view and choose 'Properties' from the drop-down menu that will appear. Under 'signing' you will have the option of choosing a key file. Choose the one you created with the SN utility, and rebuild your project.

There! You have a signed assembly, ready for installation into the GAC.

Monday, February 12, 2007

Yougle Now Installing

My next blog entry will be on writing installers.

Just to prove that I'm not COMPLETELY full of it, here's an image from my current MCML project.

Of course there's a lot of work to be done, the interface has to be prettied up a lot - but at least you know I'm not just making all of this up :)

Thinking and Transferring Data in MCML

OK, I understood the basics of this one when I started, but just to help those newbies out (for instance, there have been a few messages like this on the MediaCenterSandbox), I'll go over the code/view seperation that you find in MCML.

There are two major components of any MCML application. These are the user interface elements (the .MCML files) and the code (the C# program).

In most ocmmon programming models, your code will directly reference the controls For example, you will set the text on the button called 'Button1' to say 'Hello' with the command "Button1.Caption='Hello';" or through messages like "SetDlgItemText(IDC_BUTTON1,'Hello');".

In MCML, the user interface and your code are kept seperate. You never directly reference any controls or user interface elements from your code.

Instead, MCML has access to the properties of your objects. So basically you choose what properties you want to show on your interface and hand them to your MCML page as properties.

Your MCML page is where your object is created. You can then access all of the public properties of the object and use them in your MCML file.

An example of passing a value from C# to MCML...

So in C#, you have a class like this

public class MyObject
//The underlying data

protected string _MyStringValue;

//The property to read in MCML
public String MyStringValue
return _MyStringValue;

And then if you want an MCML text object that uses the value...

<UI Name="MyObject">

<Text Name="MyData" Color="White"/>

<a:MyStringValue Name="Val"/>
<Binding Source="[Val.MyStringValue]" Target=[MyData.Content]"/>

This assumes you are importing your C#/.NET assembly with the namespace 'a' (this is the default when you create an MCML project in Visual Studio, so you shouldn't have to add this line to the first tag of your document).

Wednesday, February 7, 2007

Navigating - and Another MCMLPad Warning

There's another minor bug/issue in MCMLPad - something you should be aware of once you start doing more advanced development.

To navigste from 'page' to 'page' (eg. between UI's) you can use the <Navigate> action within any Rule.

The only required member of this tag is URI - the address to the next page. Most frequently, this will be a link to an MCML file that you have enclosed in a resource (usually the same DLL that contains your .NET application).

You can also pass objects in this Navigate tag. Since Navigate opens another UI as the main interface, you pass objects to this new UI exactly the same way that you do between UI's in a single interface - by passing them as properties.

So, for example, you can create a property on the base-UI in 'Page2.mcml', and set it with the Navigate tag in 'Page1.mcml'. This is how you can continue to pass information between pages and propagate information through your entire application.

ONE WORD OF WARNING: MCMPad has a small glitch (I hesistate to call it a 'bug', but it IS annoying) where pressing F5 to refresh the page will NOT work correctly for any page that has been passed a property. The property will not be re-sent, which means that any strings will be reset to empty and any objects will be set to 'null', which will normally mean that MCMLPad will close with an exception.