@@ -58,6 +58,7 @@ public string Title
5858 public ICommand ClosingCommand { get ; }
5959 public ICommand ChangeSelectedWindowCommand { get ; }
6060 public ICommand SetVolumeCommand { get ; }
61+ public ICommand SwitchToSelectedWindowCommand { get ; }
6162 public ICommand MouseEnterCommand { get ; }
6263 public ICommand MouseLeaveCommand { get ; }
6364 public ICommand DpiChangedCommand { get ; }
@@ -203,6 +204,7 @@ public PiPModeViewModel()
203204 ClosingCommand = new RelayCommand ( ClosingCommandExecute ) ;
204205 ChangeSelectedWindowCommand = new RelayCommand ( ChangeSelectedWindowCommandExecute ) ;
205206 SetVolumeCommand = new RelayCommand < object > ( SetVolumeCommandExecute ) ;
207+ SwitchToSelectedWindowCommand = new RelayCommand ( SwitchToSelectedWindowCommandExecute ) ;
206208 MouseEnterCommand = new RelayCommand < MouseEventArgs > ( MouseEnterCommandExecute ) ;
207209 MouseLeaveCommand = new RelayCommand < MouseEventArgs > ( MouseLeaveCommandExecute ) ;
208210 DpiChangedCommand = new RelayCommand ( DpiChangedCommandExecute ) ;
@@ -507,6 +509,27 @@ private double GetWindowTop(Window window)
507509 return window . Top ;
508510 }
509511
512+
513+ /// <summary>
514+ /// Executed on click on set volume button. Opens <see cref="VolumeDialog"/>
515+ /// </summary>
516+ private void SwitchToSelectedWindowCommandExecute ( )
517+ {
518+ var thisWindow = ThisWindow ( ) ;
519+ var selectedHandle = this . _selectedWindow . WindowInfo . Handle ;
520+
521+ NativeMethods . ShowWindow (
522+ selectedHandle ,
523+ NativeMethods . IsZoomed ( selectedHandle ) ? ShowWindowCommands . ShowMaximized : ShowWindowCommands . Restore
524+ ) ;
525+ NativeMethods . SetForegroundWindow ( selectedHandle ) ;
526+ NativeMethods . SetActiveWindow ( selectedHandle ) ;
527+ NativeMethods . BringWindowToTop ( selectedHandle ) ;
528+ NativeMethods . SetFocus ( selectedHandle ) ;
529+ NativeMethods . SwitchToThisWindow ( selectedHandle , true ) ;
530+ SystemCommands . MinimizeWindow ( thisWindow ) ;
531+ }
532+
510533 /// <summary>
511534 /// Executed on click on set volume button. Opens <see cref="VolumeDialog"/>
512535 /// </summary>
0 commit comments