views:

65

answers:

1

I just installed VS2010 and the great new IronPython Tools extension. Currently this extension doesn't yet generate event handlers in code upon double-clicking wpf visual controls. Is there anyone that can provide or point me to an example as to how to code wpf event handlers manually in python. I've had no luck finding any and I am new to visual studio.

Upon generating a new ipython wpf project the auto-generated code is:

import clr
clr.AddReference('PresentationFramework')

from System.Windows.Markup import XamlReader
from System.Windows import Application
from System.IO import FileStream, FileMode

app = Application()
app.Run(XamlReader.Load(FileStream('WpfApplication7.xaml', FileMode.Open)))

and the XAML is:

<Window 
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       Title="WpfApplication7" Height="300" Width="300"> 
       <Button>Click Me</Button>
</Window> 

Any help would be appreciated.

+2  A: 

You can't use something like <Button Click="Foo"> here, because there is no class in code corresponding to your window, and you can't get one, because IronPython classes do not directly map to CLR classes. Also, XamlReader, which is used to load the XAML file here, does not support event wireup. If you need events, you'll have to register handlers from Python code, not in XAML - which is done by the usual += syntax once you've obtained the control for which you want the event to be registered.

Also have a look at this sample for some helpers that might make this easier.

Pavel Minaev
If I had enough points to vote you up, I would. ++Thanks
DonnyD