Skip Navigation LinksHome / Tips / Resources

Resources

+
Items Resolution

  • 0 comments  /  posted by  Denislav Savkov  on  Sep 01, 2008 (more than a year ago)

    User control static resources are used to declare instances of objects that should be alive and reusable throughout the whole life of a user control. When you declare a static resource in the Xaml of a user control Visual Studio actually declares this instance as an internal class field of that user control, thus making it directly accessible only in your code behind. Usually such things like styles and templates are declared as static resources and as result they can be used multiple times from within your control.

    Share


  • 0 comments  /  posted by  Denislav Savkov  on  Sep 01, 2008 (more than a year ago)

    Application static resources are used to declare instances of objects that should be alive and reusable throughout the whole life of an application. Usually as static resources are declared such things as styles, templates etc. Thus they can be used multiple times from multiple places within your Silverlight application.

    Xaml

       <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    x:Class="SnackBites.App"
                    xmlns:local="clr-namespace:Bomb">
           <Application.Resources>
                   <Style x:Name="simpleStyle" TargetType="Button">
                       <Setter Property="Content" Value="Static style content"></Setter>
                   </Style>
           </Application.Resources>
       </Application>
    Note that for each resource you declare x:Name or x:Key should be specified!
    That's it!
    Share
  • 2 comments  /  posted by  Denislav Savkov  on  Sep 01, 2008 (more than a year ago)

    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}.

    Share

Join the free SilverlightShow webcast 'Running Silverlight Outside the Browser and with Elevated Trust'. Sept 7th, 8 am - 9 am PDT.
In this live session Chris Anderson will cover configuring and debugging OOB mode, toast notifications, elevated trust, direct file access and much more.
Learn more | Register | See more webinars (hide this)