Getting the Info before a View is unloaded.

May 10, 2012 at 5:17 PM
Edited May 10, 2012 at 5:21 PM

Hi, I am using a small part of the Cinch framework, especially the ViewResolver, What i am doing is that using the ViewResolver to load the views and their respected ViewModels in a User Control, for a Particular view i want to do some cleanup operations on its closing/unloading

Can you please guide me how i can achieve this.

 

Also there is a method in the ViewResolver like 

public static DependencyObject CreateView(string viewName)

Can you help me to write the code for DestoryView, which will simply unloads that view and destory the View's current active object

Coordinator
May 11, 2012 at 10:38 AM
Edited May 11, 2012 at 10:39 AM

Yeah you should not be using ViewResolver  for anything other than getting a view into a workspace. YOU WOULD NOT use it for for DestroyView / Unload or anything like that

 

You should use the ViewAwareStatus for events liked Loaded/Unloaded. If you download CInchV2 and look at the WPF demo code, and have a look at MainWindowViewModel you will see a use of the ViewAwareStatus service.

 

But this should not be used to do stuff in the view. If you need to do stuff on UnLoaded in the View, that is where you should do it, the ViewAwareStatus service provides weak events that fire when the view events fire, but do not stop view from being GCd.

 

Sounds to me like you need to read this article from start to finish and look at the demo : http://www.codeproject.com/Articles/88402/CinchV2-Version2-of-my-Cinch-MVVM-framework-part-2#CoreServices look at the write up of the IViewAwareStatus service