I'm using Caliburn Micro and AvalonDock in my project. I try to handle events when screen was activated. My main view model is a 'Conductor.Collection.OneActive' and each tab "document" is a 'Screen'. I have a function in my main view model like this:
public void CheckAndRegisterDocument(DocumentViewModel document)
{
DocumentViewModel exists = _documents.FirstOrDefault((d) => { return d.Equals(document); });
// if not exists - add it
if(exists == null) {
document.Activated += Document_Activated;
_documents.Add(document);
Items.Add(document);
}
// activate and set property object
ActivateItem(document);
Properties.PropertiesObject = document.Properties;
}
// document activated event handler
private void Document_Activated(object sender, ActivationEventArgs e) {
ActiveDocument = sender as DocumentViewModel;
}
But the function "Document_Activated" is not invoked. what am I doing wrong?
Itemscollection manually, it will be added when you callActivateItem(document). And it seems like_documentsandActiveDocumentare just duplicating built-in conductor properties:ItemsandActiveItem. - Anton Kedrov_documentsandItemslooks the same and they are )... it's a result of any my experiments. I was looking for decision. I don't understand why it not working. When theActivatedevent should invoke?... And, yes, I'm not trying to activate the same Screen second time. - R. BolshakovActivateItem(document), in the class derived fromConductor<Screen>.Collection.OneActive,Activatedevent fires without any trouble. You might try to enable logging and see what CM does when you try to activate your VM: buksbaum.us/2010/08/08/how-to-do-logging-with-caliburn-micro - Anton Kedrov