How to dispose of AvaloniaUI Application #331
-
I am using AvaloniuaFuncUI to create a add-in for Excel. I can open a window and close it using the "X" button in the top right of the window. When I go to open it again I get the following error:
What is the correct way to handle this situation? I have searched the API for a way to dispose of the application and have not found one. I have also tried to open the main window again instead of launching the application again but have not found a way to do that either. Is there any documentation or guides for a scenario where you want the application to stay open and just hide/show the main window? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi Matthew! In the world of add-ins, the AppDomain belongs to the parent app (Excel), so you have to be careful not to call your app init code more than once. First of all, you have some control over the conditions that shutdown your app via the override this.OnFrameworkInitializationCompleted() =
match this.ApplicationLifetime with
| :? IClassicDesktopStyleApplicationLifetime as desktop ->
let view = MainView()
desktop.MainWindow <- view
desktop.ShutdownMode <- ShutdownMode.OnMainWindowClose Values are:
I've had to do this in the past with Revit add-ins: if (Application.Current == null)
{
var app = new Application();
app.ShutdownMode = ShutdownMode.OnExplicitShutdown;
} I know that's not a direct answer, but I hope that it's enough of a hint to put you on the right track! |
Beta Was this translation helpful? Give feedback.
Hi Matthew!
In the world of add-ins, the AppDomain belongs to the parent app (Excel), so you have to be careful not to call your app init code more than once.
First of all, you have some control over the conditions that shutdown your app via the
ShutdownMode
property:Values are:
ShutdownMode.OnMainWindowClose
ShutdownMode.OnExplicitShutdown
ShutdownMode.OnLastWindowClose
I'v…