gpt4 book ai didi

python - 将 IronPython 链接到 WPF

转载 作者:行者123 更新时间:2023-11-28 22:06:47 26 4
gpt4 key购买 nike

我刚刚安装了 VS2010 和很棒的新 IronPython Tools扩大。 Currently此扩展尚未在双击 wpf 可视控件时在代码中生成事件处理程序。有没有人可以提供或指出有关如何在 python 中手动编写 wpf 事件处理程序的示例。我没有找到任何东西,而且我是 visual studio 的新手。

在生成一个新的 ipython wpf 项目时,自动生成的代码是:

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)))

XAML 是:

<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>

如有任何帮助,我们将不胜感激。

最佳答案

你不能使用像 <Button Click="Foo"> 这样的东西在这里,因为你的窗口对应的代码中没有类,你也拿不到,因为IronPython类不直接映射到CLR类。另外,XamlReader ,用于在此处加载 XAML 文件,不支持事件连接。如果您需要事件,则必须从 Python 代码而不是 XAML 中注册处理程序——这是由通常的 += 完成的。获得要为其注册事件的控件后的语法。

另请查看 this sample对于一些可能会使这更容易的帮助者。

关于python - 将 IronPython 链接到 WPF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3057044/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com