locked
How to share resources between projects RRS feed

  • Question

  • Is there any way to share resources (say Styles) between Silverlight projects?

    I have couple of Silverlight projects and they all contain some user controls. I use every Silverlight project on a different page of an ASP.NET app. I want all the user controls to be styled the same way and I need a way to share common styles between all these projects.

    The problem exists also with sharing third-party Silverlight libraries. I reference them in all of my projects. As a result I have 10 XAP files which all contain  one (or more) same assembly and this assembly is downloaded everytime one of XAP files is loaded.

    The two problems are actually pretty different no matter it is all about sharing resources.

    I'll be glad if someone share any experience on that topic.

    Monday, November 10, 2008 9:44 AM

Answers

  • You can put your style definition in App.Xaml. Then you can use them in all your Silverlight controls no matter if they are in your Silverlight application project or the class libraries project.

    You can use them either directly in the Xaml (Style="{StaticResource YourStyleName}") or in code(Style st = Application.Resources["YourStyleName"] as Style;).

    I have couple of Silverlight projects and they all contain some user controls. I use every Silverlight project on a different page of an ASP.NET app. I want all the user controls to be styled the same way and I need a way to share common styles between all these projects.

    When you say you use every Silverlight project on a different page do you mean you have different Silverlight application for different page? If that is the case, then you have to share the App.xaml for all your Silverlight Application projects.

    Or you can have one Silverlight application project for all your pages, but use InitParameter to identify the start page(UserControl) on each ASP.NET page.  That start UserControl could be in different Silverlight class libraries. So you have only one App.xaml for all your ASP.NET pages, but load load different UserControl as start page on each ASP.NET page.

     

     

     

     

     

     

    Monday, November 10, 2008 1:08 PM
  • Another good place to figure this out is to download the SilverlightTookKit source code on www.codeplex.com.  Once you download it then unzip and review how they are doing their Themes.

    I always learn better when someone else has created an example.

    Monday, November 10, 2008 11:21 PM

All replies

  • did you try creating a seperate project and have all the styles there in that project and reference styles from that project?

    Monday, November 10, 2008 11:23 AM
  • Sure, but then how can you use them from XAML?

    Monday, November 10, 2008 11:32 AM
  • I dont think we can reference from xaml, if we do it like that unless, we create another class and point the Defaultstylekey to point to our style

    Monday, November 10, 2008 12:38 PM
  • You can put your style definition in App.Xaml. Then you can use them in all your Silverlight controls no matter if they are in your Silverlight application project or the class libraries project.

    You can use them either directly in the Xaml (Style="{StaticResource YourStyleName}") or in code(Style st = Application.Resources["YourStyleName"] as Style;).

    I have couple of Silverlight projects and they all contain some user controls. I use every Silverlight project on a different page of an ASP.NET app. I want all the user controls to be styled the same way and I need a way to share common styles between all these projects.

    When you say you use every Silverlight project on a different page do you mean you have different Silverlight application for different page? If that is the case, then you have to share the App.xaml for all your Silverlight Application projects.

    Or you can have one Silverlight application project for all your pages, but use InitParameter to identify the start page(UserControl) on each ASP.NET page.  That start UserControl could be in different Silverlight class libraries. So you have only one App.xaml for all your ASP.NET pages, but load load different UserControl as start page on each ASP.NET page.

     

     

     

     

     

     

    Monday, November 10, 2008 1:08 PM
  • Another good place to figure this out is to download the SilverlightTookKit source code on www.codeplex.com.  Once you download it then unzip and review how they are doing their Themes.

    I always learn better when someone else has created an example.

    Monday, November 10, 2008 11:21 PM
  • When you say you use every Silverlight project on a different page do you mean you have different Silverlight application for different page? If that is the case, then you have to share the App.xaml for all your Silverlight Application projects.

    Yes, at this moment I have different Silverlight applications for the different pages. How can I share one App.xaml for all Silverlight application projects?

    I'll think about merging all projects into one and loading the user controls by using an init param. Actually, I've been thinking about that before, but I was afraid from XAP file size. More controls - larger size. But may be it is still a better solution. I'll test that. Thanks!

     

     

    Tuesday, November 11, 2008 1:02 AM
  •  

    Another good place to figure this out is to download the SilverlightTookKit source code on www.codeplex.com.  Once you download it then unzip and review how they are doing their Themes.

    I always learn better when someone else has created an example.

    I learn better that way too, but only if the source is trustworthy ;). I'll check it out.  Thanks!

    Tuesday, November 11, 2008 1:07 AM
  • I am missing something. I thought the original question was.

    "if I have styleA for Textblock. how can I define it in one place so I can use it in different projects, the projects need not be in the same application"

    Tuesday, November 11, 2008 7:21 AM
  • I have merged two project both created in MS Project 2010, but when they are merged i can not share there resources, which i would like to know how or if it is possible. So can you share resources in a merged project in MS project 2010?

    Tuesday, November 30, 2010 10:33 PM