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?