请原谅,我对GUI编程、IronPython、WPF和.NET都是新手。不过,我对Python相当熟悉。我浏览了很多在线教程,但似乎没有一个能解决我所面临的问题。(也许是小事?但对我这样的人来说,这并不是小事
问题:我想知道如何从我的Windows.System.Application启动一个新的WPF窗口(XAML)。基本上,我想从我的应用程序的“帮助”菜单启动一个“关于”对话框。我知道这可以通过使用System.Windows.Forms.Form实现,但从长远来看,我希望能够通过使用XAML标记加载更复杂的窗口排列。
目前,当我单击About菜单(mnuAboutClick)时,这会加载XAML窗口,但在这个过程中会替换/销毁原始主窗口(WpfMainWindow)。我要两扇窗户都开着。
编辑:或者,是否有方法将xaml加载到System.Windows.Forms.Form中?这很适合我的需要。
下面是我的代码示例:
import wpf
from System.Windows import Application, Window
class MyWindow(Window):
def __init__(self):
wpf.LoadComponent(self, 'WpfMainWindow.xaml')
def mnuAboutClick(self, sender, e):
print 'About Menu Click'
wpf.LoadComponent(self, 'WpfAboutWindow.xaml') # How to launch "About Dialog", This works, but destroys "WpfMainWindow"!
if __name__ == '__main__':
Application().Run(MyWindow())
如果要同时显示两个窗口,则应使用
Show
(msdn)或ShowDialog
(msdn)方法。示例:
文件“AboutWindow.xaml”:
文件“AboutWindow.py”:
文件“IronPythonWPF.xaml”:
文件“IronPythonWPF.py”:
相关问题 更多 >
编程相关推荐