Living Without App.xaml (…and still being able to use Blend!)

While default WPF (and Silverlight) projects make it very easy for you to get up and running with your application for a majority of scenarios, often, there are scenarios where you want better control of your application. A good example of this scenario is the Expression Blend source code itself. We perform a number of tasks (for example, displaying a splash screen) before the main application Window is shown to you.  For making this happen, we don’t use the App.xaml concept in WPF projects, but instead go with a code generated Application object which gives us better control over how things work. We then load a number of external resource dictionaries that control the look and feel of our application into the Application’s resources.

However, the lack of App.xaml causes issues when you design your application inside Blend. Blend provides a lot of design-time experiences around App.xaml – for example, all resources in App.xaml are always available in all the projects that are referenced from the main project. This is essentially a feature that lets you easily centralize your shared resources across control libraries into one location. Another example is that we allow you to link your external resource dictionaries into App.xaml, again, to make sharing of resources easier for you.

If you ever run into this, you can use another feature in Blend to work around this issue. You can include your App.xaml into the project file on a conditional basis such that when the project is loaded inside Blend, you get the normal experience that you are comfortable with. While building your application, though, App.xaml is not included in the build process, so your code continues to work as before (for example, WPF automatically creates an entry point for your application when you build App.xaml, but you might already have an entry point defined in code).

The below sample will show how you can leverage this by just making a couple of lines of edit to your project files. Essentially, the changes to the project boil down the following two lines:

<DesignTime Condition="'$(SolutionPath)'!='' AND Exists('$(SolutionPath)')">true</DesignTime>

<ApplicationDefinition Condition="'$(DesignTime)'=='true' AND '$(BuildingInsideVisualStudio)'!='true' AND '$(BuildingInsideExpressionBlend)'!='true'" Include="App.xaml">

Download the project files from below:

slproject Download Sample

Hope this helps. If you have any questions, feel free to comment here or on our forums.



Comments (7)
  1. p { margin: 1em 0; } .style1 { background-color: #ecf4fd; } While default WPF (and Silverlight) projects

  2. p { margin: 1em 0; } .style1 { background-color: #ecf4fd; } While default WPF (and Silverlight) projects

  3. Dean Ward says:

    We had problems with this on our build server… We ended up doing the following instead of what is mentioned above:

    <ApplicationDefinition Condition="’$(DesignTime)’==’true’ AND ‘$(BuildingInsideVisualStudio)’!=’true’ AND ‘$(BuildingInsideExpressionBlend)’!=’true’ AND ‘$(BuildingSolutionFile)’!=’true’" Include="App.xaml">






  4. Unni's Blog says:

    A number of people have sought more clarity around how Blend and resources references work inside WPF

  5. jbe says:

    Alternative approaches that should work with the designer are described here:

    You might find this information useful too.

  6. Guy Hurst says:

    We are using Prism 2.1 for a WPF application and recently started using Blend 3 to edit the views – only to discover that it would not display the UI, only the XAML. By adding the App.xaml file with the ResourceDictionary references and modifying the project file with the conditions provided in this post (and Dean Ward’s reply), we can now see our UI in Blend 3.

    Thank you for this work around.

  7. Todor Tsvetkov says:

    Great Article, Unni!

    We are working on a huge project using Composite WPF (Prism) 2 with MVVM. This article realy shined light into the lives of our designers and everyone else involved in constructing the user interface.


Comments are closed.

Skip to main content