Building a .NET Micro Framework Emulator with WPF (Part 0)

The .NET Micro Framework SDK comes with a customizable emulator that allows extensions to the emulated hardware as well as the complete look and feel of the emulation experience. The sample emulator from the SDK and the emulator project templates all use windows forms for the user interface. While Windows Forms has served well for many years it isn’t without it’s drawbacks. Microsoft introduced the Windows Presentation Framework (WPF) to improve the development of user interfaces. In particular WPF places a strong emphasis on separating the presentation from the data model and the code that acts upon it. This allows for skinning applications, cleaner unit testing and isolating the development engineers from the design of the user interface.

In creating a demo application for a prototype Point of Sale/customer loyalty kiosk I wanted to have an emulator to work on the application code even when I didn’t have the hardware with me. While I could have just used the classic windows Forms UI model I wanted to have the emulator look like the actual kiosk with a non-rectangular window and LEDs that glowed like the real thing. (LEDs behind a plastic diffuser). Trying to do all of that in Windows Forms seemed like a whole lot of work. Fortunately I had a copy of Chris Sells and Ian Griffiths excellent book Programming WPF . I moved it to the top of my reading pile and had a good read. (The appendix on XAML is a must read, even for those who think they know XAML already)

I’m going to start a series of posts on building .NET MF emulators using WPF instead of Windows Forms. As I go along I’ll talk about some of the advantages of WPF and, in particular, the Model View + View Model (MV+VM) design pattern that has become popular with WPF developers.

I’ll introduce a re-usable library (Microsoft.SPOT.Emulator.Wpf) for building emulators with WPF and the MV+VM design pattern. The library includes support for another WPF pattern called attached behaviors, in particular there is support for attaching Touch Panel and GPIO button press behavior to any user interface element in XAML making it easy to support custom user interaction with your emulated device. There is also a base class for creating a View Model for a custom emulator so that you can bind it to the UI. I’ll start with just assuming you want to make a new emulator with my library and later dive into the details of the libraries implementation In part 1 I’ll go over creating a simple emulator with a WPF UI and show how a bit of good design can leave you free of the task of making the UI look good and get a custom emulator in record time. In later posts I’ll get into more advanced usage and dive into the implementation details of the Microsoft.SPOT.Emulator.Wpf library and the kiosk emulator. (Including custom interop extensions for the emulator’s hardware)