I am using Prism 4 with the MEF extensions and the MVVM pattern. During initialization in the module, I call RegisterViewWithRegion (RegionNames.MyRegion, typeof (MyView)), which works fine when the view is constructed as follows:
[Export]
[PartCreationPolicy(CreationPolicy.NonShared)]
public partial class MyView : UserControl
{
public MyView()
{
....
The view is registered, and everything is in order. As soon as I change the Export to a custom export attribute, the view can no longer be found, although it is still in the container. This custom export attribute is taken from an exchange trader RI:
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
[MetadataAttribute]
public class ViewExportAttribute : ExportAttribute, IViewRegionRegistration
{
public ViewExportAttribute()
: base(typeof(object))
{ }
public ViewExportAttribute(string viewName)
: base(viewName, typeof(object))
{
ViewName = viewName;
}
public string RegionName { get; set; }
public string ViewName { get; set; }
}
and interface
public interface IViewRegionRegistration
{
string RegionName { get; }
string ViewName { get; }
}
By changing the export attribute to
[ViewExport(ViewName = "MyView", RegionName = RegionNames.MyRegion)]
[PartCreationPolicy(CreationPolicy.NonShared)]
public partial class MyView : UserControl
{
public MyView()
{
....
when calling RegisterViewWithRegion it gives an error: an activation error occurred while trying to get an instance of type MyView, the ""
Any tips? I looked at this part of the code all day without finding a solution.