I am just starting out using IronPython with WPF and I don't quiet understand how binding is supposed to be done.
Normally in WPF I would just do something like this:
<ListBox Name="MyListBox">
<ListBox.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<DockPanel>
<TextBlock Text="{Binding Path=From}" />
<TextBlock Text="{Binding Path=Subject}" />
</DockPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.Resources>
</ListBox>
Then in my code behind:
MyListBox.ItemsSource = new ObservableCollection<Email>()
But in IronPython we cannot have an ObservableCollection of objects, only types. This does not work:
MyListBox.ItemsSource = new ObservableCollection[email]()
As it throws the Exception: "expected Array[Type], got classobj"
What am I supposed to do? Help please!
Extending on boden's answer, you may want to enhance the NotifyPropertyChangedBase a bit:
With that set, you could do sometihng like:
With that in place, you'll get the @notify_property and @property.setter items set for everything in the defineNotifiableProperty call.
I worked this out myself, I had a few things wrong and was missing a few key point as well. I hope this answer can help someone else.
First was that you need pyevent.py from the tutorial/ directory in your IronPython directory.
Second we need a helper class:
Then you need to declare your data class like so:
Finally set the ListBox's ItemSource:
Credit to this link for the help: http://palepoli.skr.jp/wp/2009/06/28/wpf-listview-databinding-for-ironpython/
IronPython is case-sensitive and does not use the
new
keyword. Try: