title: Assign image source in code-behind of XAML control
body: <p>I have the following xaml</p>
  
  <pre><code>&lt;StackPanel x:Name="StackPanelBanner" Grid.Row="1"&gt;&lt;/StackPanel&gt;
  </code></pre>
  
  <p>I had to write this much messy code to add picture to it.</p>
  
  <pre><code>var toplogoBitmap = new BitmapImage();
  toplogoBitmap.BeginInit();
  toplogoBitmap.UriSource = new Uri(@"" + _appPath + "images/toplogo.png", UriKind.RelativeOrAbsolute);
  toplogoBitmap.EndInit();
  
  var toplogoImage = new Image
  {
      Source = toplogoBitmap,
      VerticalAlignment = VerticalAlignment.Top,
      HorizontalAlignment = HorizontalAlignment.Left,
      Stretch = Stretch.None
  };
  StackPanelBanner.Children.Add(toplogoImage);
  </code></pre>
  
  <p>Because i have to get the images from folder, which will be changing on time to time, i can't put them in resources.</p>
  
  <p>Is there any short way of adding picture in XAML control. i.e</p>
  
  <pre><code>&lt;StackPanel source="toplogo" x:Name="StackPanelBanner" Grid.Row="1"&gt;&lt;/StackPanel&gt;
  </code></pre>
  
  <p>in Codebehind</p>
  
  <pre><code>var toplogo = @"" + _appPath + "images/toplogo.png";
  </code></pre>