title: Make a UserCOntrol on a Page the same size as the MainWindow in WPF
body: <p>I have a WPF application.  It consists of:</p>
  
  <ol>
  <li>A MainWindow which loads a Page which contains a UserControl.</li>
  <li>The UserControl is simply a MediaElement with play/pause controls etc.</li>
  </ol>
  
  <p>Here is the XAML for the UserControl:</p>
  
  <pre><code>&lt;UserControl x:Class="InstallerToolkit.UserControls.UserControlVideoPlayer"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
           mc:Ignorable="d" 
           d:DesignHeight="300" d:DesignWidth="464"&gt;
  &lt;Grid Margin="0,0,0,0" Background="Black"&gt;
      &lt;StackPanel  Margin="0,0,0,0" VerticalAlignment="Bottom"&gt;
          &lt;MediaElement Name="MediaElement" MediaOpened="Element_MediaOpened" LoadedBehavior="Manual" UnloadedBehavior="Stop"/&gt;
          &lt;StackPanel DockPanel.Dock="Bottom" Background="DarkGray"  HorizontalAlignment="Center" Orientation="Horizontal"&gt;
              &lt;Image Source="/Images/control_play.png" MouseDown="OnMouseDownPlayMedia" Margin="5" /&gt;
              &lt;Image Source="/images/control_pause.png" MouseDown="OnMouseDownPauseMedia" Margin="5" /&gt;
              &lt;Image Source="/images/control_stop.png" MouseDown="OnMouseDownStopMedia" Margin="5" /&gt;
              &lt;TextBlock Foreground="White" Margin="5"  VerticalAlignment="Center"&gt;&lt;Run Text="Seek To"/&gt;&lt;/TextBlock&gt;
              &lt;Slider x:Name="timelineSlider" Thumb.DragStarted="DragStarted" Thumb.DragCompleted="DragCompleted" Margin="5" ValueChanged="SeekToMediaPosition"  Width="70"/&gt;
              &lt;TextBlock x:Name="lblProgressStatus" Margin="5"&gt;&lt;Run Text="00:00"/&gt;&lt;/TextBlock&gt;
              &lt;TextBlock x:Name="lblSepatator" Margin="5"&gt;&lt;Run Text="/"/&gt;&lt;/TextBlock&gt;
              &lt;TextBlock x:Name="lblTotalLength" Margin="5" RenderTransformOrigin="3.607,0.455"&gt;&lt;Run Text="00:00"/&gt;&lt;/TextBlock&gt;
              &lt;Image Source="/images/control_stop.png" Margin="145,0,0,0" MouseLeftButtonDown="Image_MouseLeftButtonDown" /&gt;
          &lt;/StackPanel&gt;
      &lt;/StackPanel&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here is the positon of my UserControl normally:</p>
  
  <p><img src="https://i.stack.imgur.com/wBchV.jpg" alt="enter image description here"></p>
  
  <p>I have added a button to the UserControl to try and make it go the full size of the MainWindow.
  WHen I click the fullscreen button I have an event on my page which does the following:</p>
  
  <pre><code>    private void VideoPlayer_FullScreenSelected(object sender, EventArgs e)
      {            
          var parentWindowWidth = ((System.Windows.Controls.Panel)(Application.Current.MainWindow.Content)).ActualWidth;
          var parentWindowHeight = ((System.Windows.Controls.Panel)(Application.Current.MainWindow.Content)).ActualHeight;
  
          Thickness margin = new Thickness(0,0,0,0);
          VideoPlayer.Margin = margin;
          VideoPlayer.Width = parentWindowWidth;
          VideoPlayer.Height = parentWindowHeight;
  
      }
  </code></pre>
  
  <p>When I do this I see the VideoPlayer appearing larger like so:</p>
  
  <p><img src="https://i.stack.imgur.com/fT7n3.png" alt="enter image description here"></p>
  
  <p>Note how it is the size of my Page but not the MainWindow which I want ot to be.</p>
  
  <p>So then I have added an event to my Page which triggers a function in my MainWindow that tries to grab the MediaElement from my Page and make it fullscreen.  But I dont know how to grab my UserCOntrol from here and make it the size I need.</p>
  
  <p>How can I do this??</p>