Show modal dialog window from WinFormsAvaloniaControlHost #15977
-
We are in the process of converting our large WinForms application to Avalonia, we have converted several views using WinFormsAvaloniaControlHost this works great! We would like to display some modal avalonia dialog windows from the WinFormsAvaloniaControlHost avalonia view, for example when the user clicks a Button. Is this possible? We have tried access Avalonia.Application.Current.ApplicationLifetime but this value appears to be null when running inside a WinForms app. Example:
The only workaround we have found is to continue using WinForms Form dialog objects and embed a WinFormsAvaloniaControlHost inside each dialog, which is a bit messy, it would be nice if we could us the Avalonia Window object to clean this up. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Do you have a real Avalonia window? The winforms interop control runs the Avalonia control inside a winform form, not an Avalonia window. If you have an Avalonia window you can just make it display a dialogue directly. You should also be able to instantiate an Avalonia window yourself as well. Although I am not too sure how well that works with winforms. |
Beta Was this translation helpful? Give feedback.
-
I don't think it's possible with the current public API.
"After its shown" is likely to be necessary, otherwise Avalonia would redefine it with null-parent. |
Beta Was this translation helpful? Give feedback.
Thanks @maxkatz6 . I was able to get it to work following your instructions, I had to make a few changes, here is the code that worked for me to show a modal Avalonia Window from a WinForm app: