4

I'm using MVVM Light and Prism with the view model locator pattern. I really like having a design time view model for use in Blend, but I don't necessarily want to ship it with my production code. Is there any way to put the design time view model in another assembly and then tell the view model locator to find it there? It seems like the design time assemblies (*.Design.dll) would help solve this problem, but I can't quite work out how.

Mike Post
  • 6,355
  • 3
  • 38
  • 48
  • 3
    Why don't you use xaml files with the DesignData build action? I have answered the question where I've explained how to use it correctly: http://stackoverflow.com/questions/5693283/binding-data-to-a-datagrid-on-design-time/5693532#5693532 , but the guy who asked the question wanted something other than design data in the Blend. And I wonder why everyone is so reluctant to use so easy approach. – vortexwolf Apr 29 '11 at 14:36
  • I don't use DesignData because my production view models are heavily constructor dependency injected. That means no default constructor so no creating from XAML. The VML locator pattern takes care of all this for me. Even if I'm missing something and it's possible to mix DesignData with a constructor injected VM, it still leaves the problem of extra code and resources in the production assemblies. So I'll turn your question around: if I use DesignData, how do I put the design resource dictionary in another assembly and get Blend to load it without having to ship that assembly? – Mike Post Apr 29 '11 at 21:00
  • Actually there is no such problems if to clear the property CustomTool (remove the MsBuild value). After that you will be able to define a model without the default constructor. And files with this action (DesignData instead of Page or Resource) will not be included in the final assembly. If you don't believe - you can try to open the assembly using some decompiler like reflector. – vortexwolf Apr 29 '11 at 21:30
  • @vorrtex Thats for that tip - it means I need to tweak my ViewModel classes but overall it works better than defining additional classes. You do need a parameterless constructor though - even if you clear the custom tool the design-time support doesn't work without that constructor. – Justin Jan 16 '13 at 11:15

1 Answers1

4

Mike,
Add the following to your XAML..

xmlns:designTime="clr-namespace:MyDesignTimeNS;assembly=MyBinaryName"
d:DataContext="{d:DesignInstance designTime:DesignTimeObjectNameViewModel, IsDesignTimeCreatable=True}

With this, I'm able to keep my design time data in a separate binary and not distribute it.

Sam
  • 535
  • 5
  • 14
  • I hadn't thought about putting the design stuff in a separate xmlns in another assembly, nice! I've found issues with the IsDesignTimeCreatable property causing exceptions in Blend quite a bit, but that seems a separate issue. – Mike Post Apr 30 '11 at 23:34