2016-09-01 7 views
0

내 프로젝트에서 Caliburn Micro 및 AvalonDock을 사용하고 있습니다. 화면이 활성화되었을 때 이벤트를 처리하려고합니다. 내 메인 뷰 모델은 'Conductor.Collection.OneActive'이고 각 탭 '문서'는 '화면'입니다.Caliburn 마이크로 스크린 활성화 이벤트

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; 
    } 

그러나 "Document_Activated는"호출되지 않습니다 기능 : 나는 이런 내 주요 뷰 모델의 기능을 가지고있다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

+0

같은 화면을 두 번 연속 활성화하지 않으시겠습니까? –

+0

그리고 그냥 메모. 수동으로'Items' 컬렉션에 문서를 추가 할 필요가 없습니다. ActivateItem (문서)를 호출 할 때 추가됩니다. 그리고'_documents'와'ActiveDocument'는 빌트인 도체 속성 인'Items'과'ActiveItem'을 복제하는 것 같습니다. –

+0

답장을 보내 주셔서 감사합니다. 예,'_documents'와'Items'는 똑같아 보이고 ...) 내 실험 결과입니다. 나는 결정을 찾고 있었다. 왜 작동하지 않는지 나는 이해하지 못한다. 'Activated' 이벤트가 호출되어야 할 때 ... ... 그리고 네, 같은 스크린을 두 번 활성화하려고하지 않습니다. –

답변

0

문서 개체를 문서 컬렉션에 추가하는 대신 기존의 this.Items 컬렉션에 문서 개체를 추가하십시오.

또한 각 문서 개체는 참여를 위해 Screen에서 상속해야합니다.

그 +

document.ConductWith(this) 

가이 현재 도체 뷰 모델입니다 ... +해야 트릭을하기에 충분하지만, 때로는 ConductWith 통해 viewmodels을 "수행"할 Caliburn을 말할 필요가있을 수 있습니다.

+0

고마워요! ... 'ConductWith' 기능으로 완벽하게 작동합니다. –