Design Time Resources in Blend 4
- 7 June, 2010 -
- Blend, Silverlight, Tutos Docs -
- Tags : Blend 4, resources, Silverlight
- 0 Comments
Blend 4 offers new features and one of them is rather obscure at first. Now, it is possible in Expression Blend to create resources unique to the design time (at the time of conception in Blend or Visual Studio). The problem is rather trivial, it is often necessary to allocate graphics resources that are defined at runtime. In the workspace of Visual Studio or Blend, they are not resolved as they are defined at runtime. This causes access errors and some display problems. Blend 4 can now solve this problem but the manner of proceeding is not very obvious. The goal is to create a design time resource dictionary containing a resource or multiple resources that you will only use the design time. The first thing to do is create a project and a resource contained in a resource dictionary. A gradient or SolidColorBrush will do the trick (see below).
Then, delete the link defined in App.xaml. Resources are now inaccessible and you get access errors. It does not matter, you have to go through this step. Save the project and then open it again in Blend 4, you get a nice dialog box telling you whether you want to create a dictionary used in design time (see below).
Finally, create the resource via C #, it will be used by Silverlight at runtime.
In the end you get two different visual result. The first concerns the design time, the second is the visual displayed at runtime using the resource instantiated during initialization:) So, the designer is completely autonomous. Ultimately, this process is not very orthodox but it is very useful. The principle is not based on anything other than a conditional compilation, generated at the project level (. Csproj). The following code:
<Page Include="Properties\DesignTimeResources.xaml">
<Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType>
</Page>
has been replaced by this one :
<Page Include="Properties\DesignTimeResources.xaml"
Condition="'$(DesignTime)'=='true'
OR ('$(SolutionPath)'!='' AND Exists('$(SolutionPath)')
AND '$(BuildingInsideVisualStudio)'!='true'
AND '$(BuildingInsideExpressionBlend)'!='true')">
<Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> <ContainsDesignTimeResources>true</ContainsDesignTimeResources>
</Page>




