Design-time Resources in Expression Blend 4 RC

When building Silverlight and WPF applications that are composited (e.g. using MEF) or written to support UI customization, resources are loaded dynamically at run-time. This is a great solution on the development side, but can be a challenge when working on design tasks.  If your design surface can’t find the resources at design-time you are presented with zero styling or worse, XAML parsing errors.

Expression Blend 4 RC provides a new feature to support loading resources at design-time.

When you open a project in Blend and the current document contains resources that cannot be resolved and your solution contains at least one ResourceDictionary file, the Add Design-time Resource Dictionary dialog will open.

Add Design-time Resource Dictionary dialog

Once selected, a reference to the dictionary will be added to a file named “DesignTimeResources.xaml” located under the Properties folder. Blend will now find the missing resources during design-time and be able to render the design surface properly.

This feature enables editing of dynamic applications to be much easier than before. No more hacks to get your resources loaded!

—–

As a side note, if you’ve added a ResourceDictionary as a design-time resource and you’d like to remove it; open the “DesignTimeResources.xaml” file.  In XAML view, remove the reference to your resource dictionary in the ResourceDictionary.MergedDictionaries node. Then after closing and reopening the file referencing the missing resources, the dialog will prompt you again to choose a dictionary.

—–

I’ve provided a sample solution below that will prompt you with the Add Design-time Resource Dictionary dialog, when you open the “MainPage.xaml” file.

Download the Design-time Resource Sample

This entry was posted in Client Technologies and tagged , , , , . Bookmark the permalink.

7 Responses to Design-time Resources in Expression Blend 4 RC

  1. SmartyP says:

    this is going to save us a ton of headaches, thanks a bunch for showing how it works.. i know that blend 4 can support SL3 apps, does this specific functionality work for SL3 apps as well, or would this only work for an SL4 app? thanks again.

  2. Adam Kinney says:

    Good question, and the answer is YES, it works the same way with Silverlight 3 projects.

    I should put together a post of all the Blend 4 features that are useful for Silverlight 3 apps and title it “Upgrade today!”

  3. SmartyP says:

    sweet, thanks again

  4. Pingback: Dew Drop – May 5, 2010 | Alvin Ashcraft's Morning Dew

  5. Theo Albers says:

    Hi,

    This would be an extremely usefull feature within Visual Studio 2010 as well. Do you know when this feature will be lifted to VS2010?

  6. Adam Kinney says:

    @Theo Albers
    I’m not sure, but I’ll send along the suggestion to the team. I agree it is a nice feature to have supported in both editors.

  7. Valerie says:

    When you add the design time resources, Blend also adds a project reference to the project containing the resource dictionary. Does this reference only occur during design-time as well? In our project we don’t want our modules to reference the skin assemblies… we want to load them dynamically based on some settings at runtime. I already have the mechanism in place to do the dynamic loading, but I am trying to figure out a way to see our styles applied during design, while still keeping the modules “ignorant” of the skins… do you have any suggestions? Thanks!

Leave a Reply