Export a property doesn't change

Oct 17, 2011 at 8:20 AM

Hi all ,

I face a problem with exporting a property . 

I have two view model :

public class ViewModelA

{

[Export]

public LanguageObj LObj {get;set;}

}

public class ViewModelB

{

[Import]

public LanguageObj LObj {get;set;}

}

when I run the my app , the first wire between the properties is made , but at first the languageObj is null , because the user didn't select language yet . when the user select language , the property in vm A is updated , but when I try toi get it in vm B still see the null value which mean mef didn't notified about this change .

Btw , if I use propert of type ObservableCollection<LanguageObj> for example , I really see the change, which mean each change on the collection in A I see it in B.

I moved to use method export , and its working fine , but really interesting why I cann't use the property export style .

I used :

[Export(typeof(Func<LanguageObj>))]

public LanguageObj GetLanguageObj()

{

return LObj

}

and in VM B I use :

[Import]

public Func<LanguageObj>> LObj {get;set;}

 

Any ideas. 

Thanks in advance ...

Oct 24, 2011 at 10:39 PM

Hi - MEF doesn't support this out of the box. The underlying recomposition machinery, which you are expecting to kick in, could potentially support this but does not today. The Func<> based solution you have come up with is a reasonable way to do the job.

Cheers,

Nick

Oct 25, 2011 at 8:55 AM

Thanks allot . 

Do you have any explanation why this is working when I use ObservableCollection as a type of the property ?

Regards ...

Oct 25, 2011 at 3:43 PM

You're welcome.

If you use ObservableCollection, then the same collection object will be shared between the exporter and importer. Thus, changes to the contents of the collection on the exporter side will show up as changes on the importer side because the collection referenced by both sides is the same.

Hope this helps.

Nick