Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing WPF Application from a class library (Caliburn.Micro)

I have to develop a WPF application and use Caliburn.Micro to provide MVVM. But this time the view models are located in a separate class library.

All works fine, until I want to close the application. Because the view models are in a separate assembly, they can't access the applicatuion class of the WPF application. So I can't use System.Windows.Application.Current.Shutdown() to close the application, like I did in my former applications.

So how can I exit the application under this conditions?

Info about the existing class hierarchy: ViewModelBase is an abstract base class for all my view models. It derives from Caliburn.Micro.PropertyChangedBase and provides the functionality for IoC, the window manager and the event aggregator.

like image 381
ZaHaDum1984 Avatar asked Jan 27 '26 04:01

ZaHaDum1984


1 Answers

Inherit from Caliburn.Micro.Screen, which derives from PropertyChangedBase through ViewAware, and call TryClose().

Or call just call System.Environment.Exit(0).

like image 183
mm8 Avatar answered Jan 28 '26 19:01

mm8