Is it possible to execute somehow one Command from a different ViewModels in the WPF application using Prism?
Let me explain what I mean.
I have the MainMenuViewModel class:
public class MainMenuViewModel
{
private ICommand _aboutCommand;
public ICommand AboutCommand
{
get
{
if (_aboutCommand == null)
{
_aboutCommand = new DelegateCommand(() =>
{ MessageBox.Show("About menu item clicked!"); });
}
return _aboutCommand;
}
}
}
also there is the View for this model:
<Menu IsMainMenu="True">
<MenuItem Header="Nápověda">
<MenuItem Header="O Aplikaci" x:Name="About"
Command="{Binding AboutCommand}" />
</MenuItem>
</Menu>
There is another module in the application, which should execute the command with the same behavior (or even probably better - the same command):
public class MunisatorViewModel
{
private ICommand _aboutCommandInAnotherModule;
public ICommand AboutCommandInAnotherModule
{
get
{
if (_aboutCommandInAnotherModule== null)
{
_aboutCommandInAnotherModule= new DelegateCommand(() =>
{ MessageBox.Show("About menu item clicked!"); });
}
return _aboutCommandInAnotherModule;
}
}
}
this module has the View:
<StackPanel Background="White" HorizontalAlignment="Center" VerticalAlignment="Top">
<Button cmd:Click.Command="{Binding AboutCommandInAnotherModule}">About</Button>
</StackPanel>
Is it possible to avoid the duplicate code?
P.S. I understand, that I can create base class for this two ViewModels and describe this Commands there, but problem is, that some of the ViewModels has already different base classes.