views:

28

answers:

1

I've just installed IronPython 2.7 with VS support, and am trying to create a simple prototype WPF application. Something is broken, probably in my installation, and I can't figure out how to diagnose it. I can't get the simplest of bindings to work; they fail with an exception that seems really, really wrong.

I create a WPF application project, and put XAML like this in my WpfApplication1.xaml file:

<Window 
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       Title="WpfApplication1"> 
       <Grid>
          <TextBox x:Name="MyTextBox" Text="{Binding RelativeSource={RelativeSource Self}, Mode=OneWay, Path=ActualWidth}"/>
    </Grid>
</Window> 

When I run this, I get this exception:

System.Xaml.XamlObjectWriterException was unhandled by user code
  Message=Provide value on 'System.Windows.Data.Binding' threw an exception.

InnerException: System.Windows.Markup.XamlParseException
     Message=A 'Binding' cannot be set on the 'Text' property of type 'TextBox'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.

Hmm, last time I looked, Text is a dependency property. And indeed, if I create the binding in code, it works:

import clr
clr.AddReference('PresentationFramework')

from System.Windows import Application, Window, Controls, Data, PropertyPath

class MyWindow(Window):
    def __init__(self):
        clr.LoadComponent('WpfApplication1.xaml', self)
        t = self.FindName("MyTextBox")
        b = Data.Binding()
        b.RelativeSource = Data.RelativeSource.Self
        b.Mode = Data.BindingMode.OneWay
        b.Path=PropertyPath("ActualWidth")
        t.SetBinding(Controls.TextBox.TextProperty, b)

I'm pretty baffled at this point. It's hard for me to imagine anything that could cause this problem that wouldn't also mess up creating WPF objects from XAML completely. Is there something obvious that I'm missing?

A: 

This is a bug in the new WPF support. It's fixed in the current sources and so it will be fixed in the Beta 1 release. The underlying cause is that there are "schema contexts" which need to be used to get full WPF semantics that we weren't using before. It also moves to a new "wpf" module instead of being in the clr module.

Dino Viehland
Wow, really? I didn't see any mention of it in the tracker. It's a little disconcerting that they'd push out any release of IronPython with a bug in it that kept WPF binding from working.
Robert Rossney
@Robert - IronPython 2.7 is currently at alpha 1 version so I think it is acceptable to have bugs there :-)
Lukas Cenovsky
This is not "bugs." This is IronPython not supporting a fundamental use case. Really, you basically can't build WPF applications with it right now. I'm surprised that this wouldn't hold up a release, and I'm more surprised that it isn't documented. When I release alpha software that has something this big broken, I tell people it's broken.
Robert Rossney
We actually didn't know about the issue at the time of the release which is why it's not mentioned in any release notes. It wasn't fixed until we later discovered it internally. 2.7 is an alpha release and as such it's there to get early feedback not to represent something that's stable and well tested.
Dino Viehland