Loose XAML

John Conway's Game of Life in XAML/WPF using embedded Python

Following on from my series on embedding DLR scripts in XAML, I present an implementation of John Conway's Game of Life in XAML/WPF using embedded Python scripts. The game is loaded completely from loose XAML. Even the initial game state is defined in dynamically loaded XAML files!

The game is hosted in the very dynamic application described in a previous post. Below is a screen shot of the hosted Game of Life applicaiton.

WPF: Embedding DLR Scripts in XAML (Python, Ruby) - Part 6, A Very Dynamic Application

A Visual Studio 2008 Solution with the complete code listing for this series is attached to this post.

To conclude this series of posts, I will build a simple application using many of the DLR Scripting goodies presented in this series. I will use Python as the scripting language, but you could use Ruby, JScript or any other language that has bindings to the DLR.

The idea here is to write a minimalist WPF application in C#, pushing as much logic as possible into the XAML and DLR Scripts, and as you will see, we end up with very little logic in the C# code!

WPF: Embedding DLR Scripts in XAML (Python, Ruby) - Part 5, A DLR Event Handler

A Visual Studio 2008 Solution with the complete code listing for this series is attached to the final part.

As discussed in the previous article, GUIs are all about layout, style and wiring. WPF has the first two in spades; XAML is an excellent language for doing layout and styling of WPF GUI elements. However, sorely lacking in WFP is the ability to route commands and events in dynamically loaded XAML. This makes any attempt to build truly dynamic XAML based GUIs near on impossible as at some point you will have to handle an event, but it is hard enough to route an event to a static method let alone have a script execute in response to an event being fired!

Inspired by Josh Smith's work, I demonstrate how to use an attached property to establish a DLR script as an event handler for any WPF routed event.

WPF: Embedding DLR Scripts in XAML (Python, Ruby) - Part 4, A DLR Command

A Visual Studio 2008 Solution with the complete code listing for this series is attached to the final part.

GUIs are all about layout, style and wiring. WPF has the first two in spades; XAML is an excellent language for doing layout and styling of WPF GUI elements. However, sorely lacking in WFP is the ability to route commands and events in dynamically loaded XAML. This makes any attempt to build truly dynamic XAML based GUIs near on impossible as at some point an event is going to need handling or a command issued.

Continuing the series on embedding DLR scripting in XAML, here I demonstrate how to implement a scripted WPF Command, making dynamically loaded XAML one step closer to being a first class citizen in the WPF world.

WPF: Embedding DLR Scripts in XAML (Python, Ruby) - Part 3, A DLR Value Converter

A Visual Studio 2008 Solution with the complete code listing for this series is attached to the final part.

The WPF Binging class is very powerful and its use should be encouraged. However, it can be cumbersome to do some very simple things with it, introducing a barrier to its use. One such barrier is defining a ValueConverter.

A ValueConcverter is a class that can convert the source property value of a binding before it is set on the target property. Often such conversions are simple expressions that do not warrant the creation of a new class - though this is what is done.

The first article in this series demonstrated how to host the DLR and presented some utility methods that make executing scripts simple. Here we build upon this to create a ValueConverter that evaluates a DLR expression that supports two way binding.

WPF: Embedding DLR Scripts in XAML (Python, Ruby) - Part 2, A Simple DLR Markup Extension

A Visual Studio 2008 Solution with the complete code listing for this series is attached to the final part.

This article demonstrates how to embed DLR scripts in XAML using a custom MarkupExtension. The scripting language can be any language supported by the DLR, such as Python or Ruby.

The first article in this series demonstrated how to host the DLR and presented some utility methods that make executing scripts simple. Here we build upon this to create a simple MarkupExtension that evaluates a DLR expression.

WPF: Embedding DLR Scripts in XAML (Python, Ruby) - Part 1, Hosting the DLR

A Visual Studio 2008 Solution with the complete code listing for this series is attached to the final part.

The XAML framework allows us to easily switch between the Declarative and Imperative programming models easily. Examples such as event handlers are obvious cases where this happens, while others, such as MarkupExtensions and ValueConverters for Bindings are not so clear - when you implement the ProvideValue method of a custom MarkupExtension, you are suddenly in the the imperative world of C# (or CLR language of your choice) where as the XAML document that declared the MarkupExtension is declarative in nature.

The ability to dynamically load XAML using the XamlParser class allows the programmer to switch in and out of the declarative and imperative worlds with ease, affording them great power and flexibility. Or so it would seem...

Dynamically loaded XAML does not integrate with the imperative world as well as it's compiled brethren. For example, you completely lose the ability to route events to handlers when loading XAML dynamically. This greatly hampers the usefulness of dynamically loaded XAML. The stance in the community is that you should simply compile your XAML if you want to handle events. In many instances this is just not an acceptable solution!

There are a number of interpreted (hence dynamic) imperative languages that bind to the CLR, such as Python and Ruby. The new Dynamic Language Runtime (DLR) will encourage the development off new dynamic languages as well as the binding of existing dynamic languages to .NET. In this series of 6 articles I will demonstrate how to embed any and all DLR languages in XAML.

Subscribe to RSS - Loose XAML