IronPython – Windows Presentation Foundation Tutorials

 | December 11, 2008 3:38 pm

After finishing the download manager of my podcast aggregator (PodCatcher), I took a few days off to work on other things. After a brief break, though, I am back at the grindstone and I can happily say that it is starting to come together.

The next major component of the aggregator that I will work on is the library module. This will include the functions necessary to view, add, remove and manage the different Podcast feeds and the individual podcast episodes. Due to my initial architecture, I have hit a patch of luck.

Since the aggregator sits on top of the Windows RSS Platform, much of the "library" functionality is already handed to me. Further, because Internet Explorer uses the RSS platform and the Common Feeds List, there will be a nice integration with other programs. The ability to subscribe to new podcasts from the browser always made more sense to me than the model of other aggregators, where management occurs exclusively in the Podcast Manager.

Since much of the backend is already written, I have been thrown into a realm of programming where I have done very little work: the user interface. While I touched on the user interface a little in the Learning IronPython series, I have now gotten serious about it. The screenshot shows the subsequent result. I have a prototype user interface for PodCatcher!

While putting the UI together, however, I discovered a bit of a surprise.  According to the Oracle of Google, there isn't a lot of material on WPF and dynamic languages. What is worse, getting the UI to load and function isn't as simple as applying stock C# principles. To answer my (many) questions I have spent quite a bit of time hunting down tutorials and looking at everything I can find about IronPython and WPF. After trundling through Google, the IronPython users archive, MSDN, and the major IronPython blogs, I have a pretty good list and I thought it might be of interest to others trying to learn IronPython.

The Basics – Hello World to Event Handlers

When getting started, it's best to start with the basics.  As a rite of passage in every programming language, the Hello World Application seemed to make perfect sense for those learning WPF and IronPython. Luckily, there are a diverse number of examples and styles for loading a Window and sending salutations to the world.

  1. Discovering IronPython - Hello World WPF Sample. This post describes how to create a WPF window and load in Xaml from a file.
  2. WPF – Example – Working with the StackPanel. This example shows how to create a StackPanel and add elements to it. In contrast to the previous example, all of the manipulation occurs in the code behind.
  3. WPF – GUI Events Example. How to load a GUI from a XAML form and hook up events to event handlers dynamically.
  4. A Multithreaded Hello. How to load a window and launch a BackgroundWorker that counts to 100. (I know, it's a shameless plug.)

Building on the Basics

While loading windows and hooking up event handlers is useful, it can only get you so far. WPF includes a wealth of additional features like DataBinding, DataTemplates, Triggers, Styles and dozens of other powerful features. it is fortunate that there are a few IronPython specific articles which touch upon how these work with a dynamic language.

An excellent place to start is the IronPython and [Insert MSFT Technology Here] series over on DevHawk. The series begins with six posts about how IronPython works with WPF. They all describe a single project (a photo viewer for a Live.com photo feed), so there is a very nice continuity amongst the articles.

  • IronPython and WPF – Part 1. In the first article, the ground is set by describing the sample project. Though there isn't a link to them in the first post, you can find the sample files for the project here.
  • IronPython and WPF – Part 2 : Loading Xaml. This article describes how to compose a user interface in Blend and load it by using a Python script. It is a variation on the Hello World Tutorials above. While it covers a lot of old ground, it also includes a description of how to use C# with custom hooks so that WPF and IronPython play nicely together.
  • IronPython and WPF – Part 3 : DataBinding. This article is a must read for anyone interested in WPF and IronPython. It gives a great overview of DataBinding and how IronPython work together. DataBinding is a technology which works wonderfully, but requires a strategy.
  • IronPython and WPF – Part 4 : Background Processing. WPF, like Windows Forms, only has a single GUI thread. As a result, long-running processes can clog it and make the UI unresponsive. This article gives a nice overview about how to move functions into the background using Python decorators.
  • IronPython and WPF – Part 4.1 : Background Processing Revisited. In this addendum to IronPython and WPF – Part 4, the author looks at an alternative method to perform the background processing. It also links to a very interesting article that describes SynchronizationContext.
  • IronPython and WPF – Part 4.2 : Background Processing Re-Revisted. This secondary addendum to IronPython and WPF – Part 4 looks at a more elegant way to perform background processing via decorators.
  • IronPython and WPF – Part 5 : The Interactive Console. In this article DevHawk looks at how to implement a loop so that he can interact with his program when it is running. I have used a similar method for poking around inside PodCatcher. As you might imagine, it is very, very valuable to see what objects are loaded and what methods are available.

Tools

Anyone who has been poking around IronPython for a while has probably stumbled across IronPython Studio, a fantastic tool for working with IronPython from within Visual Studio. When playing with Windows Forms, it works beautifully. However, there are some limitations when using WPF.

Additional Examples?

Admittedly, this list is a bit sparse. Do you know of any additional tutorials or resources? If so please post them in the comments or send them my way. I will also add to the list as I find more material.

Similar Posts:

No Responses to “IronPython – Windows Presentation Foundation Tutorials”