[IronPython] overriding methods from C# classes
Lukas Cenovsky
cenovsky at bakalari.cz
Fri Jul 9 20:55:03 CEST 2010
On 9.7.2010 19:17, Dino Viehland wrote:
> This is one of the reasons why I suggest WPF over WinForms. In WPF you can
> declare the event handlers in the XAML and we can wire them up to you. In
> our IronPython 2.7 source code I recently added a clr.LoadComponent method which
> does this. So for WPF the code ends up looking like:
>
> import clr
> clr.AddReference('PresentationFramework')
>
> from System.Windows import Application, Window
>
> class MyWindow(Window):
> def __init__(self):
> clr.LoadComponent('WpfApplication16.xaml', self)
>
> def Button_Click(self, sender, e):
> pass
>
>
>
> if __name__ == '__main__':
> Application().Run(MyWindow())
>
>
> While the XAML looks like:
>
> <Window
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
> Title="WpfApplication16" Height="300" Width="300">
> <Grid>
> <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="152,116,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click" x:Name='Foo' />
> </Grid>
> </Window>
>
>
> And we'll both connect MyWindow.ButtonClick() to the event handlers as well as make Foo (the name of the button) available on the self instance.
>
This is very nice enhancement. Thanks.
--
-- Lukáš
More information about the Ironpython-users
mailing list