title: C#/WPF Resize Window to MediaElement's Original Content size
body: <p>I have a Window which a dynamically size with it's content (MediaElement). </p>
  
  <p>For this I use a Window with the Attribute <code>SizeToContent="WidthAndHeight"</code>.
  My MediaElement is set like this <code>Stretch="Uniform" StretchDirection="DownOnly"</code>.</p>
  
  <p>With those Settings the Window will be as big as the original size of the MediaElement Control. But Stretching is set to DownOnly and I'd like the possibility to make the window bigger.
  But when i set the Attribute StretchDirection to Both, the Window will be Maximized when I load another Movie with MediaElement.</p>
  
  <p>I would like that the Window has the Size of the MediaElement, but when I make the Window bigger I want that the MediaElement is getting bigger too.</p>
  
  <p>Thanks for your help in advance!</p>
  
  <p>This is the WPF Window</p>
  
  <pre><code>&lt;base:ContentWindow x:Class="ExplorerExtension.WindowsMediaWindow" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:base="clr-namespace:ExplorerExtension" ShowActivated="False" 
  WindowStyle="None" ResizeMode="CanResizeWithGrip" SizeToContent="WidthAndHeight"&gt;
      &lt;Grid&gt;
          &lt;MediaElement x:Name="MediaEL" MediaOpened="MediaEL_MediaOpened"
                    LoadedBehavior="Manual" Stretch="Uniform" StretchDirection="DownOnly"/&gt;
      &lt;/Grid&gt;
  &lt;/base:ContentWindow&gt;
  </code></pre>
  
  <p>And the Code</p>
  
  <pre><code>    public WindowsMediaWindow()
      {
          InitializeComponent();
          MediaEL.Source = new Uri("---");
      }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/A04Vr.jpg" alt="Picture of the Window"></p>
  
  <p>Note: All Videos have different sizes, so I can't set a fixed Width or Height</p>