Python with wpf

Hi everyone

I’m trying to import wpf.
I’ve put IronPython.Wpf.dll - this file I have not found in the Rhino IronPython plugin - in the same directory as my main script, and I have written the following:

import cls
clr.AddReference('IronPython.Wpf')
import wpf
from System.Windows import Application, Window


class...

There is another more elegant way?

It has worked well but only the first time I run it. The following I get this: Message: Cannot create more than one System.Windows.Application instance in the same AppDomain.

Does anyone know how to do?

Thanks

Juan

I haven’t used WPF from Python, only from C#. I’m pretty sure you don’t need Application, only WIndow to show a window. As you’re already inside the Rhino3D application, you can basically use Window.Show(). No need for Application.

Thanks menno

I solved with:

.Run(nameApplication)

I do not know how to use here Window.Show().

I have another doubt: how to destroy domains in WPF?

Hey Juan!

Can you please explain how you did succeed with this problem?

Kind regards,
Daniel

import System
import Rhino

window = System.Windows.Window()
System.Windows.Interop.WindowInteropHelper(window).Owner = Rhino.RhinoApp.MainWindowHandle()
window.Show()

Does this help?

Juan Expósito

I found another solution:

clr.AddReference('IronPython.Wpf')
import wpf

from System.Windows import Application, Window

class MyWindow(Window):
    def __init__(self):
        wpf.LoadComponent(self, 'WpfApplication1.xaml')
    
    def ListBox_SelectionChanged(self, sender, e):
        pass

if __name__ == '__main__':
    MyWindow().Show()

I do not know the difference at this point but thanks a lot for your fast reply!

Regards,
Daniel