Hi,
try following demo:
<Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
StartupUri="MainWindow.xaml">
<Application.Resources>
<local:ViewModel x:Key="vm"/>
</Application.Resources>
</Application>
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel DataContext="{Binding Source={StaticResource vm}}">
<Button Content="SubWindow1" Command="{Binding}" CommandParameter="SubWindow1" Margin="10"/>
<Button Content="SubWindow2" Command="{Binding}" CommandParameter="SubWindow2" Margin="10"/>
</StackPanel>
</Window>
<Window x:Class="SubWindow1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="SubWindow1" Height="450" Width="800">
<StackPanel DataContext="{Binding Source={StaticResource vm}}">
<Button Content="SubWindow1" Command="{Binding}" CommandParameter="SubWindow1" Margin="10"/>
<Button Content="SubWindow2" Command="{Binding}" CommandParameter="SubWindow2" Margin="10"/>
</StackPanel>
</Window>
<Window x:Class="SubWindow2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="SubWindow2" Height="450" Width="800">
<StackPanel DataContext="{Binding Source={StaticResource vm}}">
<Button Content="SubWindow1" Command="{Binding}" CommandParameter="SubWindow1" Margin="10"/>
<Button Content="SubWindow2" Command="{Binding}" CommandParameter="SubWindow2" Margin="10"/>
</StackPanel>
</Window>
Public Class ViewModel
Implements ICommand
Private _wnds As Dictionary(Of String, Window)
Private ReadOnly Property Wnds As Dictionary(Of String, Window)
Get
If Me._wnds Is Nothing Then
_wnds = New Dictionary(Of String, Window)
_wnds.Add("MainWindow", Application.Current.MainWindow)
_wnds.Add("SubWindow1", New SubWindow1)
_wnds.Add("SubWindow2", New SubWindow2)
End If
Return Me._wnds
End Get
End Property
Public Event CanExecuteChanged As EventHandler Implements ICommand.CanExecuteChanged
Public Sub Execute(parameter As Object) Implements ICommand.Execute
Dim wnd As Window = wnds(parameter.ToString)
If wnd IsNot Nothing Then
If wnd.Visibility = Visibility.Visible Then wnd.Hide() Else wnd.Show()
End If
End Sub
Public Function CanExecute(parameter As Object) As Boolean Implements ICommand.CanExecute
Return True
End Function
Protected Overrides Sub Finalize()
For Each kvp In Me._wnds
kvp.Value.Close()
Next
End Sub
End Class
Result: