Using Blend with Prism Apps in Silverlight 3

    Lately I have been immersed in the world of MVVM/Silverlight and often Prism. But in this world the design elements can’t be pushed aside. I admit it … I am a developer who has fallen in love with Blend! So I was pretty unhappy (Ok, I was very frustrated) when I started using Prism apps and breaking the apimageps into separate decoupled modules and found that Blend could not see the resources at design time. Basically, I usually have a handful of projects (modules) and they are completely decoupled from each other. Only 1 has need for an App.xaml, the shell module. This works great … except that the modules without the app.xaml cannot see the resource at design time in Blend. I am not willing to give up using Blend to design, so I started searching the web and asking some experts on the Blend team about options.

    It quickly became obvious to me that the adoption of Prism developers who use the completely decoupled module loaders and Blend users were not as large as I had thought. For the issue to be a problem you have to develop with Silverlight and Prism, choose to use the module catalogs to load the apps, use Unity, refrain from referencing projects directly, and design with Blend. Luckily I found some excellent help from the Blend’y guys (Peter Blois and Bob Brumfield) and Prism’y guys (Glenn Block). The solution is from their excellent advice and is as follows:

    • Put all the resources in resource dictionaries (I chose to put them in my infrastructure project, but that is up to you)
    • Add an app.xaml to each module (project)
    • Add a link to the resource dictionary in each of the app.xaml files.
    • Go to this link and follow the instructions that tell you how to add some lines to your csproj (or vbproj) files for the modules with app.xaml files. This will tell Blend to use them and to ignore the app.xaml files when you compile.

    So you end up with the best of both world: you get to design in Blend and ignore the extra app.xaml’s when you compile/build.

    Hope this helps!

    #1 Adam Wolf on 7.15.2009 at 11:24 PM

    Thank you, I have the same problem with my Silverlight prism application. Just when I was getting use to bailing out to VS to compile and run your blog came up in my reader. Thanks for the Info.

    Adam



    #2 Nasir Aziz [HydroMan] on 7.16.2009 at 12:37 AM

    That's exactly the approach I used while hoping that I wasn't breaking any rules. Seems like I was doing the right thinkg all along. Thanks for the post and confirming my approach. Cheers!



    #3 Noclegi Ziemia Klodzka on 7.16.2009 at 4:20 AM

    You say it like it's a bad thing. Blend is great and there's no shame in falling in love with it. Actualy there is some shame in NOT falling in love with it ;)



    #4 Michael Wolf on 7.16.2009 at 3:32 PM

    agreed... yes this is a great approach. Yet still it is difficult for a designer to see the app as a complete unit w/ prisim module loading.

    also .... I agree w/ not being ashamed... blend is one of the things that makes this stack so valuable and different. With out blend sl/wpf would not be adopted as widely as it is.



    #5 SmartyP on 8.05.2009 at 12:34 PM

    thanks for sharing, we are running into similar hurdles here on our Prism project, looking forward to giving this a whirl, thanks again!



    #6 Richard on 8.12.2009 at 1:11 PM

    Too bad this approach doesn't work with VS Designer (Cider)...Does anyone know how to make Cider recognize resources accorss projects?



    #7 GreatIntellect on 8.14.2009 at 10:48 AM

    I might be doing something wrong. When I link the resource dictionary. I only see the Link in the Resources window of Blend. I do not actually see the individual item templates. It looks like it will work but I cannot browse my resource dictionary when working within individual modules. Any ideas?



    #8 John Papa on 8.14.2009 at 10:50 AM

    GreatIntellect ... If I understand you correctly, you are seeing the link to the resource dictionary itself. Double click it and it should open for you. Then you can view and edit them.



    #9 Alex on 8.19.2009 at 4:21 PM

    Thanks for sharing. Do you have the instructions to add to project files. Link you provide give me forbidden access



    #10 Silverlight 3 + Twitter = Tweetup « Silverlight.Begin() on 8.26.2009 at 12:54 AM

    Pingback from Silverlight 3 + Twitter = Tweetup « Silverlight.Begin()



    #11 Steve on 10.17.2009 at 9:15 AM

    Prism should update their templates to support Blend today.

    Work around hacks are fine, but they should fix it.

    P&P seems to be creating alot of 'abandonware' (Unity comes to mind) - they are promoting good 'patterns and practices' they should dog food their own code...