title: How to set a background image by code on windows phone?
body: <p>My question is very simple but I don't find a solution that works.</p>
  
  <p>I code a Windows Phone app and I have to change the background. The change depends of the user profile on the application. If the user is a male, the app display a blue background, if she is a female, a pink one.</p>
  
  <p>I've tried to bind the background but I still have a blink effect (black to the background image).
  It is very visible when the app navigates between two pages but invisible when the change is made on the same page.</p>
  
  <p>I tried these solutions too but the background stay black:</p>
  
  
  
  <pre class="lang-csh prettyprint-override"><code>string uri = String.Format("/Assets/Background{0}.png", App.Context.SelectedUser.IsMan ? "Boy" : "Girl");
          var imageBrush = new System.Windows.Media.ImageBrush
          {
              ImageSource = new BitmapImage(new Uri(uri, UriKind.Relative))
          };
          this.Background = imageBrush;
  
  
  
  string uri = String.Format("/Assets/Background{0}.png", App.Context.SelectedUser.IsMan ? "Boy" : "Girl");
          var imageBrush = new System.Windows.Media.ImageBrush
          {
              ImageSource = new BitmapImage(new Uri(uri, UriKind.Relative))
          };
          App.RootFrame.Background = imageBrush;
  </code></pre>
  
  <p>I tried with .jpg and .png image file but none works.</p>
  
  <p>Is my code wrong?
  Anyone has a suggestion?</p>
  
  <p>Thanks a lot :-)</p>