Friday, 25 January 2013

Static Resource Binding

1.Create a resource using markup (XAML)  under  " Page or Window "  tag  .
(depending upon the type of application.....).
e.g.

 Under  Page Tag.

    <Page.Resources>
             <SolidColorBrush x:Key="bgcolor" Color="green"/>
             <SolidColorBrush x:Key="fgcolor" Color="yellow"/>
   </Page.Resources

Under  Window Tag.

    <Window.Resources>
             <SolidColorBrush x:Key="bgcolor" Color="green"/>
             <SolidColorBrush x:Key="fgcolor" Color="yellow"/>
   </Window.Resources>


2. Let us now bind the above created resource with Button. like this:

   <Button Background="{StaticResource bgcolor}"  Foreground="{StaticResource fgcolor}" Height="32">                      
         A button with Resource attached to it.        
   </Button>

3. Now Run Your Application ...........F5.

NOTE :
bgcolor: Background Color.
fgcolor : Foreground  Color







1 comment:

  1. Thank you sir. Your code really works and it was very helpful. :)

    ReplyDelete