I figured it out on my own, and here is what I did:
I created an Interface, called ICloseable, that will be used in the code-behind:
namespace MyProgram.Interfaces
{
public interface ICloseable
{
void Close();
}
}
In my ApplicationViewModel.cs, I add a command to close the window:
...
public ICommand CloseWindow_Command { get; private set; }
...
public ApplicationViewModel()
{
...
CloseWindow_Command = new RelayCommand<ICloseable>(CloseWindow);
...
}
...
public void CloseWindow(ICloseable window)
{
if (window != null)
{
window.Close();
}
}
...
In a given window, I add the name of the window in the main declaration (unique value for each window), and add that name as a CommandParameter in the Close button (which calls the close command):
<Window x:Class="MyProgram.Window1"
x:Name="theWindow1"
... >
...
<Button Height="16" Width="45"
Content="Close" FontSize="9"
Command="{Binding AppVM.CloseWindow_Command}"
CommandParameter="{Binding ElementName=theWindow1}"
ToolTip="Close this window"/>
...
And here is the code-behind for the given window, adding the Interface ICloseable:
namespace MyProgram
{
public partial class Window1 : Window, ICloseable
{
public Window1()
{
public ApplicationViewModel AppVM = ApplicationViewModel.Instance;
InitializeComponent();
}
}
}