Recommended

Skip Navigation LinksHome / Tips / View Tip

Tip: How to use static resources?

+ Add to SilverlightShow Favorites
2 comments   /   posted by Denislav Savkov on Sep 02, 2008
(0 votes)
Categories: Resources

Static resources are declared in Silverlight with the only idea to be reused from multiple places in your code. For example, when you declare a style as a static resource on application level, then this style can be referenced and applied to any control in that application. The syntax when you reference a declared static resource is as follows: {StaticResource resourceName} - where resourceName should be replaced with the name of the declared resource. See the example below:

Xaml

   <Button Style="{StaticResource simpleStyle}" x:Name="pushMeButton" Cursor="Hand"></Button>

As you can see the Button's Style property is set to be equal to {StaticResource simpleStyle}. Thus runtime the appropriate style will be taken from the current control's or application's resources and applied to that button. You do not have to specify where the resource should be taken from: whether from the application or from the user control resources.

That's it!

Share


Comments

Comments RSS RSS
  • RE: How to use static resources?  

    posted by Parag Mehta on Sep 02, 2008 21:17

    Why do you guys are posting useless posts ? You made 3 posts for useless and pretty basic things, just don't post for the sake of posting.

  • RE: How to use static resources?  

    posted by iiordanov on Sep 02, 2008 23:48

    Hi Parag,

    I hope you have noticed that this is the Tips section of the site. When it comes about tips there is no useless tip, right? Whether one tip is useful or not depends ONLY on the level of experiance of the visitor. Silverlight is a new technology and this site is made to serve not only the advanced users but also the ones that ask themselfs very basic questions such as 'How to use static resources'. If you find one tip to be very basic, then just skip it, I am pretty sure that you will find others that will be useful also to you. We are adding constantly new tips...

    Best Regards
    Ilia Iordanov

    SilverlightShow

Add Comment

 
 

   
  
  
   
Please add 3 and 4 and type the answer here:

Help us make SilverlightShow even better and win a free t-shirt. Whether you'd like to suggest a change in the structure, content organization, section layout or any other aspect of SilverlightShow appearance - we'd love to hear from you! Need a material (article, tutorial, or other) on a specific topic? Let us know and SilverlightShow content authors will work to have that prepared for you. (hide this)