InfoQ

News

PyBinding: Python Scripting for XAML

Posted by Jonathan Allen on Feb 04, 2010

Community
.NET
Topics
Dynamic Languages
Tags
XAML ,
WPF ,
IronPython

WPF developers often find themselves with an unappetizing choice. They have to either pollute their code-behind files with special case logic or create value converter classes, most of which will only be used once. PyBinding offers a third option, embedding small scripts right inside the XAML.

For example, let us say you want a block of text to be visible only if a data-bound property is non-zero. With PyBinding, you can set do this by binding the Visibility property to a fragment of IronPython code.

<TextBlock Visibility="{p:PyBinding BooleanToVisibility($[.OpenIssues]>0)}">

BooleanToVisibilty is a straight IronPython function that is defined in your application’s StartupScript.py file. The fragment “($[.OpenIssues]” refers to the OpenIssues property of the current data context. If you omit the leading dot, it would instead bind to a control with the name OpenIssues.

In testing, we have found PyBinding to have a brief performance impact while the DLR and IronPython are loaded. Once in memory, an informal review showed no significant difference between using PyBinding and fully compiled value converters.

PyBinding is available on Codeplex under the MIT license. It currently works with VS 2008 and .NET 3.5, but you can recompile it to target .NET 4.0. It does not currently support Silverlight.

What's wrong with code behind by clem clem Posted Feb 7, 2010 9:07 PM
Re: What's wrong with code behind by Assaf Stone Posted Feb 10, 2010 10:48 AM
  1. Back to top

    What's wrong with code behind

    Feb 7, 2010 9:07 PM by clem clem

    That's a good tip but why do so many developers in the MVVM world try to have zero code in the code behind ?
    At least it's the code behind is strongly typed.

  2. Back to top

    Re: What's wrong with code behind

    Feb 10, 2010 10:48 AM by Assaf Stone

    Code behind couples how the client looks with how it behaves. This causes brittleness that force you to rewrite your behavioral code when you wish to either reskin your application, or out-source your GUI+user-experience to a UX expert (3rd party firm, or even the designer in the next cubical).

Educational Content

Rails in the Large: How Agility Allows Us to Build One Of the World's Biggest Rails Apps

Neal Ford shows what ThoughtWorks learned from scaling Rails development: infrastructure, testing, messaging, optimization, performance.

Stuart Halloway on Clojure and Functional Programming

Stuart Halloway discusses Clojure and functional programing on the JVM in depth, and touches on the uses of a number of other modern JVM languages including JRuby, Groovy, Scala and Haskell.

Orion Henry and Blake Mizerany on Heroku

Orion Henry and Blake Mizerany talk about the technology behind Heroku and the benefits of the new add-on system.

Security for the Services World

Chris Riley presents security issues threatening service based systems, examining security threats, presenting measures to reduce the risks, and mentioning available security frameworks.

Navigating The Rapids:Real-World Lessons in Adopting Agile

This talk investigates technical issues encountered when moving to an Agile process.

Codename "M": Language, Data, and Modeling, Oh My!

Don Box and Amanda Laucher present “M”, a declarative language for building data models, domain models or external DSLs. Don Box's demos show some of M’s features and latest changes of the language.

SOA Manifesto - 4 Months After

It is four months since the SOA manifesto was announced; InfoQ interviewed the original author’s to get insight into the motivations and the process behind the initiative.

Memory Barriers and JVM Concurrency

This article explains the impact memory barriers, or fences, have on the determinism of multi-threaded programs.