locked
Referencing Blend resources and brush in Visual Studio w/ C# code (chutch15) - 1/29/2008 7:59 AM PST RRS feed

  • Question

  • By: chutch15


    How do you reference Blend resources and brush in Visual Studio w/ C# code?  
    I have created, for example, a few colors and gradients in Blend and added 
    them to a Resource Directory.  I should not have to recreate these in C#.
    
    What is the syntax to reference these Blend-build resources?
    
    Thanks!
    Friday, February 22, 2008 4:48 PM

All replies

  • By: Corrado Cavalli [MVP]

    Let's suppose you have a resource like this one:
    
    <Application.Resources>
      <SolidColorBrush x:Key="scb">Red</SolidColorBrush>
     </Application.Resources>
    
    you can reference it from code using FindResource
    
      private void Button_Click (object sender, RoutedEventArgs e)
      {
       this.Background = (SolidColorBrush)this.FindResource("scb");
      }
    
    -- 
    Corrado Cavalli [Microsoft .NET MVP-MCP]
    UGIdotNET - http://www.ugidotnet.org
    Weblog: http://blogs.ugidotnet.org/corrado/
    
    Monday, February 25, 2008 6:36 PM
  • By: chutch15

    Beauty, eh?!  Thanks!
    
    "Corrado Cavalli [MVP]" wrote:
    
    > Let's suppose you have a resource like this one:
    > 
    > <Application.Resources>
    >   <SolidColorBrush x:Key="scb">Red</SolidColorBrush>
    >  </Application.Resources>
    > 
    > you can reference it from code using FindResource
    > 
    >   private void Button_Click (object sender, RoutedEventArgs e)
    >   {
    >    this.Background = (SolidColorBrush)this.FindResource("scb");
    >   }
    > 
    > -- 
    > Corrado Cavalli [Microsoft .NET MVP-MCP]
    > UGIdotNET - http://www.ugidotnet.org
    > Weblog: http://blogs.ugidotnet.org/corrado/
    > 
    Monday, February 25, 2008 6:37 PM