开发者

Linking IronPython to WPF

I just installed VS2010 and the great new IronPython Tools extension. Currently this extension doesn't yet generate event handlers in code upon double开发者_JAVA技巧-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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜