title: How to load image to WPF in runtime?
body: <p>It seems like it's quite complicated to load an image in runtime to a WPF window.</p>
  <pre><code>Image image;
  image = new Uri(&quot;Bilder/sas.png&quot;, UriKind.Relative);
  ????.Source = new BitmapImage(image);
  </code></pre>
  <p>I'm trying this code, but I need some help to get it to work. I get some red lines below the code! I also wonder if I need to add some extra code inside the XAML code or is in enough with this:</p>
  <pre><code>&lt;Image Height=&quot;200&quot; HorizontalAlignment=&quot;Left&quot; Margin=&quot;12,12,0,0&quot; Name=&quot;image1&quot; 
         Stretch=&quot;Fill&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;350&quot; /&gt;
  </code></pre>
  <p>Wonder because I have seen examples with sorces to the images inside the XAML tags.</p>
  <p>EDIT:</p>
  <p>I'm using this now:</p>
  <pre><code>var uri = new Uri(&quot;pack://application:,,,/sas.png&quot;);
  var bitmap = new BitmapImage(uri);
  image1.Source = bitmap;
  </code></pre>
  <p>The XAML:</p>
  <pre><code>&lt;Grid Width=&quot;374&quot;&gt;
      &lt;Image Height=&quot;200&quot; HorizontalAlignment=&quot;Left&quot; Margin=&quot;12,12,0,0&quot; Name=&quot;image1&quot; Stretch=&quot;Fill&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;350&quot; /&gt;
      &lt;Button Content=&quot;Start&quot; Height=&quot;23&quot; HorizontalAlignment=&quot;Left&quot; Margin=&quot;12,226,0,0&quot; Name=&quot;btnStart&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;75&quot; /&gt;
      &lt;Button Content=&quot;Land&quot; Height=&quot;23&quot; HorizontalAlignment=&quot;Left&quot; Margin=&quot;287,226,0,0&quot; Name=&quot;btnLand&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;75&quot; /&gt;
      &lt;ComboBox Height=&quot;23&quot; HorizontalAlignment=&quot;Left&quot; Margin=&quot;110,226,0,0&quot; Name=&quot;cmbChangeRoute&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;156&quot; /&gt;
  &lt;/Grid&gt;
  </code></pre>
  <p>EDIT 2:
  My issue is solved, this code works fine:</p>
  <pre><code>BitmapImage image = new BitmapImage(
      new Uri(&quot;pack://application:,,,/Resources/&quot; + company + &quot;.png&quot;));
  image2.Source = image;
  </code></pre>