View on a view not shown

Oct 31, 2010 at 9:34 PM

Hello,

I'm using MEF with CM and i have masterdetail viewmodel (Screen) with two subviewmodels loaded by MES and contentcontrols

    [Import("CustomerGrid")]
    public CustomerGridViewModel CustomerGrid
    {
      get { return GridViewModel as CustomerGridViewModel; }
      set { GridViewModel = value; }
    }

    [Import("CustomerDetail")]
    public CustomerDetailViewModel CustomerDetail
    {
      get { return DetailViewModel as CustomerDetailViewModel; }
      set { DetailViewModel = value; }
    }

So far so good, but on the detail i want to display data of another view
So i added some MEF on the customerdetail-viewmodel

    [Import("RelationDetail")]
    public RelationDetailViewModel RelationDetailViewModel { get; set; }

The MEF stuff seems to work but the instantiation of the view does not seem to work

This customer detail has a content control for the relation data
    <ContentControl x:Name="RelationDetail" Width="400" Height="300" Grid.Row="2"/>

Do i have to program something to get this view initialised.
For the Masterdetail viewmodel this was not needed. all views come up as expected.

 

Oct 31, 2010 at 11:26 PM

Shouldn't the name of ContentControl be "RelationDetailViewModel" ? 

Nov 1, 2010 at 6:05 AM

Yeah, you're right, but i checked that in an earlier version... Never mind.

  [Export("RelationDetail", typeof(RelationDetailViewModel))]
  public class RelationDetailViewModel : Screen
  {
    [Import("RelationData")]
    public Relation Relation { get; set; }

  }

Strange that in CustomerViewModel (wich contain the grid and the detail) i use

    //masterdetail viewmodel

    [Import("CustomerGrid")]
    public CustomerGridViewModel CustomerGrid
    {
      get { return GridViewModel as CustomerGridViewModel; }
      set { GridViewModel = value; }
    }

    [Import("CustomerDetail")]
    public CustomerDetailViewModel CustomerDetail
    {
      get { return DetailViewModel as CustomerDetailViewModel; }
      set { DetailViewModel = value; }
    }


    //masterdetail view
    <ContentControl x:Name="CustomerGrid" Grid.Row="1"/>
    <ContentControl x:Name="CustomerDetail" Grid.Row="2"/>


   //customergrid viewmodel
  [Export("CustomerGrid", typeof(CustomerGridViewModel))]
  public class CustomerGridViewModel : GridViewModel<Customer>

  // customerdetail viewmodel
  [Export("CustomerDetail", typeof(CustomerDetailViewModel))]
  public class CustomerDetailViewModel : DetailViewModel<Customer>

Nov 1, 2010 at 5:32 PM
Edited Nov 1, 2010 at 5:33 PM

The form <ContentControl x:Name="RelationDetail" /> (which uses the naming convention) would usually work in the CustomerDetailView, given that CustomerDetailViewModel exposes a property named RelationDetail (and exposing a RelationDetailViewModel).

You can also try with the explicit binding:  <ContentControl cal:View.Model={Binding RelationDetail}" /> 

You should also check that the RelationDetailViewModel is injected BEFORE the binding occurs (using a constructor injection) or you have to provide change notification for the RelationDetail property, otherwise the change from null to the MEF provided instance will not be updated in the UI.

Nov 2, 2010 at 6:52 AM

I guess that is probably the case. I'm quite new to this MEF stuff. I will do some testing with the constructor injection.

Thanks for your reply.