title: UWP Programatically change background image of XAML page c#
body: <p>I have been searching for a while and honestly I haven't solved this really simple issue. I have a flyout menu and I have attached an event to a flyout menu item. I want to change programmatically the background image of my XAML page when I select the item.</p>
  
  <pre><code>&lt;Grid x:Name="main"&gt;
      &lt;Grid.Background&gt;
          &lt;ImageBrush Stretch="Fill" ImageSource="Assets/bg_1.jpg"/&gt;
      &lt;/Grid.Background&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>This is the default image I got as a background (the grid is basically the whole page).</p>
  
  <p>The C# event code is here:</p>
  
  <pre><code>private void MenuFlyoutItem_Click(object sender, RoutedEventArgs e)
  {
      main.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri("ms-appx:///MTG Life Counter/Assets/bg_2.jpg")) , Stretch = Stretch.None};
  }
  </code></pre>
  
  <p>When I select the menu item instead of setting the image as background, it makes it white. </p>
  
  <p><a href="http://i.stack.imgur.com/MKsoD.jpg" rel="noreferrer">Default background</a></p>
  
  <p>I tested and it is not an issue of the image. I know that I am doing something like an obvious mistake but I am a bit new to UWP and I couldn't find a solution.</p>
  
  <p><a href="http://i.stack.imgur.com/vtgiL.png" rel="noreferrer">Here is the blank background after I select to change it</a></p>
  
  <p>Thanks for you time and sorry for the ignorance. </p>