简体   繁体   中英

Catel: Fire Events after InitializeAsync in ViewModel

At startup of my application I test some connections to other systems. I fire events to get viewmodels informed of the state of this connections.

I use a Catel TabControl to show my views. I set LoadTabItems to "EagerLoading" and subscribe to the events in the method InitializeAsync in my ViewModels.

The problem is the events are fired before all viewmodels are created. How to get informed when all viewmodels are initialized to check the connections and fire the events.

I recommend you create a service or manager called ConnectionManager . This will check for the events (since this is a long living object, probably registered in the IoC container). Then in your vm, it doesn't matter if the events are already fired or not, the ConnectionManager will give you the answer.

Remember that view models are short living objects (they are gone as soon as your views are gone). If you want to maintain state, use managers / services.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM