title: How to make a StackPanel fit its Children's width
body: <p>I'm writing down here because I'm having lots of issues with this thing, and I hope you will be able to help me out :P</p>
  
  <p>I want to create a dynamic StackPanel that fits all its Children's width. I'll make you an example.</p>
  
  <p>Let's say my StackPanel is currently empty. Its Width will be 10 (f.e.) and its fixed Height is 30. Then I want to add an Image, and I wrote this down:</p>
  
  <pre><code>BitmapImage myImage = new BitmapImage(new Uri("[PATH]"));
  Image realImage = new Image();
  realImage.Source = myImage;
  realImage.Width = 50;
  realImage.Height = myImage.Height;
  myStackPanel.Children.Add(realImage);
  </code></pre>
  
  <p>The StackPanel does not enlarge to 50px though; it's stuck to 10px, cutting my image. the same happens when I try to add other UI Elements, like TextBlocks and so on.</p>
  
  <p>I tried to do something like</p>
  
  <pre><code>myStackPanel.Width += realImage.Width;
  </code></pre>
  
  <p>But of course it didn't work. I've tried to set the StackPanel's Width to "Auto", but it didn't help either. This is the StackPanel declaration in the XAML:</p>
  
  <pre><code>&lt;Window x:Name="MainWindow1" x:Class="Proj.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="myTitle" Height="480" Width="640"
      Loaded="onLoad" Background="Black" MinHeight="480" MinWidth="640"&gt;
      &lt;Grid&gt;
          ...(Other Closed Tags)...
          &lt;StackPanel Orientation="Horizontal" Name="myStackPanel" Height="30" Margin="135,283,458,147"/&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>I need a StackPanel because I have to show a dynamic bar with a variable number of objects that will perform a marquee effect on the screen, sliding from right to left. I don't know neither the number of the objects nor the final width of my dynamic bar.</p>
  
  <p>Of course, if you know there is an other way to do it, I'll be glad to learn something about it :)</p>
  
  <p>Thank you!</p>