- The PyBinding MarkupExtension: use Python statements for Data Binding
- Huge limitation of a MarkupExtension
Many of us have felt the need to have custom expressions inside of Bindings. The need has ranged from applying mathematical operators to calling methods on bound objects. For simple needs you can probably create a custom IValueConverter or a IMultiValueConverter that can do the job, but when you want to use arbitrary expressions, something more elaborate is needed. The ScriptConverter class that I blogged about earlier provides the underpinning for the PyBinding MarkupExtension. The MarkupExtension provides a simplified way of using the ScriptConverter by automatically setting up the Bindings used in the Python statements. Thus the PyBinding extension provides you the following:Rob Oakes has also been thinking about IronPython and data binding. He's written a blog entry with great coverage of the subject. It doesn't show much code, but there is promise of a follow up entry.
- Allows use of IronPython for scripting arbitrary expressions
- Each expression will be converted to a Binding or a MultiBinding depending on the number of subexpressions
- A syntax for specifying the sub-expression. Essentially a DSL for creating Bindings
In Windows Forms programming, much of the data binding occurs within the Visual Basic or C# code. WPF, however, is substantially different in that much of the syntax required for data binding appears alongside the XAML that defines the user interface. While it is possible to provide the syntax necessary for data binding from either XAML or code, it is easier to do some things from one location rather than the other. As my language of choice when working with WPF is Python, it should be mentioned that it is sometimes necessary to do things from code rather than from XAML. Defining how data should be presented in the XAML while managing the data source from the Python appears to work well.