Download new IronPython WPF window

Feel me, I'm new to GUI programming, IronPython, WPF and .NET. However, I am pretty familiar with Python. I have looked through a lot of online manuals, but none of them relate to the exact problem I encountered. (Perhaps this is trivial? But it’s not so easy for someone like me!)

Problem. I would like to know how to start a new WPF window (XAML) in a new window from my Windows.System.Application. Basically, I want to launch the "About" dialog in the help menu of my application. I know this can be achieved with System.Windows.Forms.Form, but in the end I want to be able to load more complex windows using XAML markup.

Currently, when I click "About" (mnuAboutClick), this loads the XAML window, but the process is replacing / destroying the original main window (WpfMainWindow). I want both windows to stay open.

EDIT: Alternatively, is there a way to load xaml into System.Windows.Forms.Form? That would be suitable for my needs.

Here is an example of my code:

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()) 
+4
source share
1 answer

If you want to display two windows at the same time, you must use Show ( msdn ) or ShowDialog ( msdn ).

Example:

File "AboutWindow.xaml":

 <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="AboutWindow" Height="300" Width="300"> <Grid> <TextBlock Text="AboutWindow" /> </Grid> </Window> 

File "AboutWindow.py":

 import wpf from System.Windows import Window class AboutWindow(Window): def __init__(selfAbout): wpf.LoadComponent(selfAbout, 'AboutWindow.xaml') 

File "IronPythonWPF.xaml":

 <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="IronPythonWPF" Height="300" Width="300"> <StackPanel> <Menu> <MenuItem Header="About" Click="MenuItem_Click" /> </Menu> <TextBlock Text="MainWindow" /> </StackPanel> </Window> 

File "IronPythonWPF.py":

 import wpf from System.Windows import Application, Window from AboutWindow import * class MyWindow(Window): def __init__(self): wpf.LoadComponent(self, 'IronPythonWPF.xaml') def MenuItem_Click(self, sender, e): form = AboutWindow() form.Show() if __name__ == '__main__': Application().Run(MyWindow()) 
+6
source

Source: https://habr.com/ru/post/1490045/


All Articles