none
Multiple project sharing the same style files.

    Question

  •  Hello,

    I have multiple silverlight project that I would like to use the same styles, colour scheme, and some templated objects.

    How do I accomplish this? No dynamic loading or anything, I want to see real-time update during design time in blend.

    Monday, February 15, 2010 3:54 PM

Answers

  • You can create a separate silverlight project which will contain the common style file in form of a Resource Dictionary. To do so follow the steps below:

    1. Right click on the solution in Visual Studio Solution Explorer

    2. Select 'Add New Project Option'

    3. Select 'Silverlight' from the available option on the left hand side

    4. Select 'Silverlight Class Library' project.

    5. Delete default Class1.cs file from the newly added project.

    6. Now right click on the newly added project and select 'Add New Item' option

    7. Select Silverlight and Add 'Silverlight Resource Dictionary' to the project.

    8. Copy all your styles to into the ResourceDictionary.xaml file under <ResourceDictionary></ResourceDictionary> tag.

    build the application.

    9. Now add the reference of newly created project to the silverlight project where you want to use it.

    10. Once you add the reference, go to app.xaml and write following xaml in order to add merge dictionary for common resource dictionary

     
     <Application.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="/ResourceDictionaryApplicationNamespace;component/ResourceDictionary.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
     <Application.Resources>
     

     

    Now build the application. Open the application in Expression Blend. You will be able to access all the styles in blend that resides in ResourceDictionary.xaml.

     

    Mark as answered if this answers your question.

     

    Thanks & Regards,

    Nirav Patel

    Tuesday, February 16, 2010 1:45 AM

All replies

  • Why don't you place your files and templated controls in a common-assembly?
    Monday, February 15, 2010 4:49 PM
  • You can create a separate silverlight project which will contain the common style file in form of a Resource Dictionary. To do so follow the steps below:

    1. Right click on the solution in Visual Studio Solution Explorer

    2. Select 'Add New Project Option'

    3. Select 'Silverlight' from the available option on the left hand side

    4. Select 'Silverlight Class Library' project.

    5. Delete default Class1.cs file from the newly added project.

    6. Now right click on the newly added project and select 'Add New Item' option

    7. Select Silverlight and Add 'Silverlight Resource Dictionary' to the project.

    8. Copy all your styles to into the ResourceDictionary.xaml file under <ResourceDictionary></ResourceDictionary> tag.

    build the application.

    9. Now add the reference of newly created project to the silverlight project where you want to use it.

    10. Once you add the reference, go to app.xaml and write following xaml in order to add merge dictionary for common resource dictionary

     
     <Application.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="/ResourceDictionaryApplicationNamespace;component/ResourceDictionary.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
     <Application.Resources>
     

     

    Now build the application. Open the application in Expression Blend. You will be able to access all the styles in blend that resides in ResourceDictionary.xaml.

     

    Mark as answered if this answers your question.

     

    Thanks & Regards,

    Nirav Patel

    Tuesday, February 16, 2010 1:45 AM