2013-03-31 5 views
0

내 프로젝트에서 내 클래스와 신호를 보내기 위해 MEF와 specificaly IEventAggregator를 사용하고 있는데, IEventAggregator에서의 가져 오기가 만족스럽지 않고 값이 NULL로 유지됩니까? 내가 빠진 것이 있습니까? UserControls에서 MEF에서 가져올 수 있습니까?가져 오기가 UserControl 내에서 만족스럽지 않음

public partial class MyControl : UserControl 
    { 
     public MyControl() 
     { 
      InitializeComponent(); 
     } 

     [Import] 
     public IEventAggregator EventAggregator { get; set; } 

     public void SomeMethod() 
     { 
      EventAggregator.GetEvent<ErrorMessage>.Subscribe(SomeOtherMethod); 
     } 

    } 

답변

1

UserControl에서 가져 오기를 선언 할 수 있지만 가져 오기를 충족해야합니다. WPF가 UserControl (예 : DataTemplate 통해)을 만들면 WPF에 MEF에 대한 고유 한 지원이 없기 때문에 가져 오기가 해결되지 않습니다. 당신이해야 할 일은 귀하의 CompositionContainer을 통해 귀하의 MyControl 인스턴스를 구하거나 귀하의 UserControl을 작성한 후에 SatisfyImportsOnce으로 전화하는 것입니다.

+0

CompositionInitializer.SatisfyImports (this); – user1470618

관련 문제