title: How do I transfer a wpf media element to a new parent element without the media restarting?
body: <p>I have a media element that plays MP4 files in my WPF application. I added a minimize button that transfers the media element to a smaller canvas (Minimizing) but the media restarts every time the button is clicked. I need it to continue playing from where it left off. How should I do this? Pausing the media before clicking the minimize button allows it to continue playing where it left off, but does not work consistently.          </p>
  
  <pre><code>    public void ResumeMethod() 
      {
          Show_MediaScreen.Position = Show_MediaScreen.Position;
  
          stopWatch.Start();
          dispatcherTimer.Start();
  
          Show_MediaScreen.Play();
  
  
          btnPlayTiny.Visibility = Visibility.Hidden;
          btnPauseTiny.Visibility = Visibility.Visible;
          btnPlay.Visibility = Visibility.Hidden;
          btnPause.Visibility = Visibility.Hidden;
      }
      public void PauseMethod()
      {
          Show_MediaScreen.Position = Show_MediaScreen.Position;
  
          if (stopWatch.IsRunning)
          {
              stopWatch.Stop();
          }
          // elapsedtimeitem.Items.Add(currentTime);
          btnPauseTiny.Visibility = Visibility.Hidden;
          btnPlayTiny.Visibility = Visibility.Visible;
  
          btnPlay.Visibility = Visibility.Hidden;
          btnPause.Visibility = Visibility.Hidden;
          Show_MediaScreen.Pause();
      }
  
  private void ShowMediaScreen_MinimizeControl(object sender, RoutedEventArgs e)
      {
  
  
          Show_MediaScreen.Height = 200;
  
          Show_MediaScreen.Width = 250;
  
          VideoScreen.MouseEnter += new System.Windows.Input.MouseEventHandler(ShowMediaScreen_Hover_ON);
          VideoScreen.MouseLeave += new System.Windows.Input.MouseEventHandler(ShowMediaScreen_Hover_OFF);
  
          MyCanvas.Visibility = Visibility.Visible;
          MyCanvas_Max.Visibility = Visibility.Collapsed;
  
  
          try
          {
              PauseMethod();
  
              FullSize.Children.Remove(Show_MediaScreen);
  
              MyCanvas_Mini2.Children.Add(Show_MediaScreen);
  
              ResumeMethod();
  
  
          }
          catch { }
  
  
  
          btnPlay.Visibility = Visibility.Hidden;
          btnPause.Visibility = Visibility.Visible;
  
  
  
      }
  </code></pre>