Search code examples
wpfvisual-studio-2010expression-blend-4

Blend unable to display design time data which Visual Studio 2010 can display


I have had a look at Another Question, however the error I am getting is more specific.

This sample data uses a view model, which does not have a default parameterless constructor, it does have a public parameterised one though.

I believe that design time data uses reflection and should be able to deal with this (as it doesn't actually instantiate the class). Hence it confuses me as to why I get the following error at design time:

The type "AccessDeniedViewModel" does not include any accessible constructors.

The line in my XAML, which includes the design time data is d:DataContext="{d:DesignData /SampleData/AccessDeniedViewModelSampleData.xaml}". I used Blend's 'Create Sample Data from Class...' to generate this data file.

When I open this view in Visual Studio 2010 however, it is fully able to display it along with the design time data.

I do not really want to place parameterless constructors merely for use at design time, any way to get this design data working in Blend would be very much appreciated.

EDIT: I should also mention, the binding support is still there, when I add bindings to the view, the available properties are listed, like it is resolving to the correct type, just unable to instantiate it.


Solution

  • You will need to supply a default constructor. Here is why: Why XML-Serializable class need a parameterless constructor

    The only other option I can think of is writing logic in your view's constructor which loads the xaml at design-time so you are able to call the parameterized versions of the constructors.