locked
Silverlight 2 and Resources RRS feed

  • Question

  • What is the standard, best practise for using StaticResources in Silverlight 2?

    I recently found out that I cannot use a ResourceDictionary like I use in WPF. That was handy because I could keep like resources in seperate files (Resources/brushes.xaml etc.) and merge them into the dictionary.

    In Silverlight 2, I can define resources in App.xaml Application.Resources section, but I cannot seem to access them from another namespace. For example, I have App.xaml and the resources defined in a assembly/namespace something like: Company.Project.Silverlight. I have several user controls defined within the same assembly in the Company.Project.Silverlight.Controls namespace. If a UserControl there references a StaticResource define in App.xaml it locks up the browser.

    I can put the resource in the user control's UserControl.Resources section and it works fine. However, this defeats the purpose of having one global place to define resources.

    Am I missing something?

    Monday, June 2, 2008 12:04 PM

Answers

  • Yes, the current beta1 release dose not support ResourceDictionary.

    But I have been putting the Application level style definitions in the App.xaml and I have controls in other name space( and in other Control Library assembly dll) using those styles without problem. You might have to add your extra name space in your App.XAML; and when you trying to define Style for those controls, do not forget the prefix

    <Application xmlns="http://schemas.microsoft.com/client/2007"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 x:Class="YourCompany.Silverlight.App"         
                 xmlns:controls="clr-namespace:YourCompany.Silverlight.Controls;assembly=YourControlAssebmly">

            <Style TargetType="controls:MyControl" x:Key="MyControlStyle">

           </Style>
     

    </Application> 

    Monday, June 2, 2008 12:27 PM

All replies

  • Yes, the current beta1 release dose not support ResourceDictionary.

    But I have been putting the Application level style definitions in the App.xaml and I have controls in other name space( and in other Control Library assembly dll) using those styles without problem. You might have to add your extra name space in your App.XAML; and when you trying to define Style for those controls, do not forget the prefix

    <Application xmlns="http://schemas.microsoft.com/client/2007"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 x:Class="YourCompany.Silverlight.App"         
                 xmlns:controls="clr-namespace:YourCompany.Silverlight.Controls;assembly=YourControlAssebmly">

            <Style TargetType="controls:MyControl" x:Key="MyControlStyle">

           </Style>
     

    </Application> 

    Monday, June 2, 2008 12:27 PM
  • I ended up having to delete and re–create my App.xaml file and re–set it as the startup object in order for it work.  Not sure what was wrong…

    Thursday, June 19, 2008 4:06 PM