DesignTime support in Caliburn Micro for cascaded ViewModels is broken #358

Closed
beachwalker opened this Issue Aug 24, 2016 · 4 comments

Projects

None yet

2 participants

@beachwalker
beachwalker commented Aug 24, 2016 edited

I have put the Bootstrapper in a separate assembly than ViewModels and Views.
However the DesignTime support seems to work for simple _ViewModel->_View visualizations when there is no other Screen embedded that needs to resolve the corresponding view. But I can't get it running for child ViewModels. I get an Exception instead...

Container with Child ViewModel:

<UserControl ...
    d:DataContext="{d:DesignInstance Type=vm:DesignSomeContainerViewModel, IsDesignTimeCreatable=True}"
    cal:Bind.AtDesignTime="True ... >
  <ContentControl cal:View.Model={Binding PropertyWithChildModel} />
  // where PropertyWithChildModel is another Screen

The Screen within the Property is working correctly when displaying on it's own at DesignTime but not inside the ContentControl of another View... then the DesignTime support gets broken. I followed the guidance as suggested here Caliburn Micro Documentation. But there is nothing said about specialties when using nested resolving.

My project structure:

[Application.exe]
- MyNameSpace.ApplicationName
  - Bootstrapper (knows assemblies with views)
[Satellite.dll]
- MyNameSpace.SomeWhere
  - SomeContainerViewModel
    - [DesignTime]/DesignSomeContainerViewModel (Folder is Namespaceprovider)
  - SomeContainerView (SomeContainerView is set to look at DesignSomeContainerViewModel at DesignTime)
  - [MyChilds]/SomeChildViewModel
    - [DesignTime]/DesignSomeChildViewModel
  - [MyChilds]/SomeChildView (SomeChildView is set to look at DesignSomeChildViewModel)

Class model:

public interface ISomeChildViewModel
{
    string SomeValue {get;}
}

// should not be used during design time
public class SomeChildViewModel : Screen, ISomeChildViewModel
{
     // real implementation
}

// this is used at design time
public class DesignSomeChildViewModel : Screen, ISomeChildViewModel
{
   public DesignSomeChildViewModel()
   {
       this.SomeValue = "Hello World!";
       // showing up correctly in the Xaml View at DesignTime
   }

    string SomeValue {get;set;}
}

public interface ISomeContainerViewModel
{
    IScreen PropertyWithChildModel{get;}
}

// should not be used during design time
public class SomeContainerViewModel : Screen, ISomeContainerViewModel
{
    // real implementation
}

// used during design time
public class DesignSomeContainerViewModel : Screen, ISomeContainerViewModel
{
   public DesignSomeContainerViewModel ()
   {
       // this assignment leads to an exception that the IoC is not ready
       // "IoC is not initialized."
       this.PropertyWithChildModel = new DesignSomeChildViewModel();
   }

    IScreen PropertyWithChildModel
    {
       get { return propertyWithChildModel; }
       set
       {
            this.propertyWithChildModel=value;
            this.NotifyOfPropertyChange();
       }
    }
}

What I already tried/checked:

  • Bootstrapper: list of assemblies from SelectAssembly contains assembly with Views
  • ViewModelLocator: was set to match against DesignTime ViewModel instead of ViewModel (even if not, there should be a message that the View can't be resolved for the ViewModel)
  • used Conductor with ActiveItem instead of simple property
  • the container DesignSomeContainerViewModel and SomeContainerViewModel share same interface with IScreen PropertyWithChild {get;} and binding points to the right property

I use Caliburn.Micro 3.0.1 (current nuget package).

This issue is also posted as question at stackoverflow.

@beachwalker

It seems it has something to do with the bootstrapper and the custom IoC. However, even when adding InDesignMode checks this does not help. (I use Autofac instead of builtin IoC.)

@beachwalker

#359 has also an example close to this topic that breaks the VS Designer.

@beachwalker

Hmm, nobody else stepped into this trap yet?

@nigel-sampson
Contributor

I've pushed a fix for this that should resolve it.

@nigel-sampson nigel-sampson added the bug label Nov 9, 2016
@nigel-sampson nigel-sampson added this to the v3.0.2 milestone Nov 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment