Method OnDeactivate is not called if view is clossing

Jan 7, 2011 at 10:40 AM

Hi I download latest realese of Caliburn.Micro and I am little confuse with behavior of WindowManager.ShowWindow();

For example I have some view model for WPF window view:

    [Export(typeof(IChatViewModel))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class ChatViewModel : Screen, IViewModelIdentity, 
        IChatViewModel, 
    {..}

I create instance of this class with MEF and show thiw window with ShowWindow method.

Something like this:

        ExportLifetimeContext<IChatViewModel> chatScreen = ViewModelControler.CreatChatViewModel();

                _windowManager.ShowWindow(chatScreen.Value);

It call method OnActive in ChatViewModel class. For this momemt is all OK.

Then I close this view (WPF window) but in ChatViewModelClass is not called OnDeactivate method.

This method is call only if all application is closing.

It is normal ? If I close some view his method OnDeactivate is not called? Because if I use previous release of Caliburn.Micto it call method OnDeactivate everytime if I close some view (WPF window).

Thank, for explanation.

Coordinator
Jan 7, 2011 at 12:53 PM

I may have introduced a bug recently. Can you make a repro and send it to me asap at robertheisenberg at hotmail dot com Thanks!!

Jan 7, 2011 at 1:59 PM
EisenbergEffect wrote:

I may have introduced a bug recently. Can you make a repro and send it to me asap at robertheisenberg at hotmail dot com Thanks!!

Sory Mr. Eisenberg maybe now look as fool, what is repro ? :/ Repro means Visual Studio project with application?

In previous version I use method Show() it works good, I only use new release of Caliburn.Micro and use ShowWindow method and it cause this problem.

 

Coordinator
Jan 7, 2011 at 2:08 PM

Yes, if you can send me a VS solution that demonstrates the problem as simply as possible, that would help me to get it fixed quicker.

Jan 7, 2011 at 3:19 PM
EisenbergEffect wrote:

Yes, if you can send me a VS solution that demonstrates the problem as simply as possible, that would help me to get it fixed quicker.

Sory Mr. Einseberg I try make simple application and it call OnDeactivate method, but in my complex application it doesn’t call OnDeactivate method when is window closing.

But if I change dlll and use old caliburn.dll it works. If you wish I can send all project,and detail described where is it problem.

I check everything...code is the same, only changes are in caliburn dll.

 

In simple app I use ANTS memory profiler and I see  new window manager kill view instace after window is closed is very good. But in my comples application it doesn’t call OnDeactivate method.

Jan 7, 2011 at 3:34 PM

I created a simple problem to check into the issue, but I must say that there is no problem with the default WindowManager/Screen implementation, since the OnDeactivate is called as expected.

Moreover, the current implementation does not differ so much from the old WindowConductor point of view, so it's quite strange that you are experiencing such issue... considering this and the other issue, I fear there is some problem with your application...

Jan 7, 2011 at 5:15 PM

Mr. Einsenberg and BladeWise I would like to give you justify I was a wrong. I view  I have this code:

 

        //private bool _mClose;

        //public ChatView()
        //{
        //    InitializeComponent();
        //}

        //public new void Close()
        //{
        //    _mClose = true;
        //    base.Close();
        //}

        //private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        //{
        //    if (_mClose)
        //    {
        //        return;
        //    }
        //    e.Cancel = true;
        //    Hide();
        //}

This was my problem...I am fool but it was very  old block of code and I did forget it :( I would like to justify if I will cause you some trouble.

Coordinator
Jan 7, 2011 at 5:41 PM

You caused no trouble. Don't worry about it. It's better to post here and be mistaken then not to and waste a lot of time on a real bug. Often times the process of creating the repro helps to solve the problem itself, and if it doesn't it helps me to figure things out much quicker.

Jan 7, 2011 at 5:55 PM
Edited Jan 7, 2011 at 5:57 PM
EisenbergEffect wrote:

You caused no trouble. Don't worry about it. It's better to post here and be mistaken then not to and waste a lot of time on a real bug. Often times the process of creating the repro helps to solve the problem itself, and if it doesn't it helps me to figure things out much quicker.

I am glad, thank for clemency