title: Update ImageBrush from ResourceDictionary at runtime
body: <p>In my WP7 application, all the pages use an ImageBrush as the background that I have defined in a ResourceDictionay. This ResourceDictionary is merged globally through the App.xaml. The ImageBrush in the ResourceDictionary is defined like this:</p>
  
  <pre><code>&lt;ImageBrush x:Key="PhonePageBackground" ImageSource="/Background1.jpg"/&gt;
  </code></pre>
  
  <p>Im trying to update the ImageSource of the ImageBrush at runtime, but its not working. </p>
  
  <p>Making some tests, where I have a page with a button on it to change the background, I realized that the code below works fine:</p>
  
  <pre><code>    ImageBrush image;
  
      public MainPage()
      {
          InitializeComponent();
  
          image = new ImageBrush { ImageSource = new BitmapImage(new Uri("/Background1.jpg", UriKind.Relative)) };
  
          LayoutRoot.Background = image;
      }
  
      private void button1_Click(object sender, RoutedEventArgs e)
      {
          image.ImageSource = new BitmapImage(new Uri("/Background2.jpg", UriKind.Relative));
      }
  </code></pre>
  
  <p>But the code below, where I use the ImageBrush from the dictionary, does not work. The background of the page becomes transparent, as if the image could not be found:</p>
  
  <pre><code>    ImageBrush image;
  
      public MainPage()
      {
          InitializeComponent();
  
          image = (ImageBrush)Application.Current.Resources["PhonePageBackground"];
  
          LayoutRoot.Background = image;
      }
  
      private void button1_Click(object sender, RoutedEventArgs e)
      {
          image.ImageSource = new BitmapImage(new Uri("/Background2.jpg", UriKind.Relative));
      }
  </code></pre>
  
  <p>Both images (Background1.jpg and Background2.jpg) build action are set as Content. I've tested with Resource set, but without success.</p>
  
  <p>Any knowledge of why this behavior?</p>