(X) Hide this
    • Login
    • Join
      • Generate New Image
        By clicking 'Register' you accept the terms of use .
        Login with Facebook

Tip: How to declare static resources in the scope of a Silverlight user control?

(8 votes)
Denislav Savkov
Denislav Savkov
Joined Feb 11, 2008
Articles:   14
Comments:   6
More Articles
0 comments   /   posted on Sep 02, 2008
Tags:   static-resources , denislav-savkov
Categories:   General

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.


 <UserControl x:Class="SnackBites.MySilverlightControl"
      Width="400" Height="300">
          <Style x:Name="simpleStyle" TargetType="Button">
             <Setter Property="Content" Value="Static style content"></Setter>
     <Grid x:Name="LayoutRoot" Background="White">
Note that for each resource you declare, either x:Name or x:Key should be specified!
That's it!



No comments

Add Comment

Login to comment:
  *      *       
Login with Facebook