You can do this in several ways - adding a link to a window may work because the view model is not related to the view, but is related to it, but I don't really like this approach, since it pretty much matches your viewmodel - actually this is not the point of MVVM
A better approach might be to have your viewmodel raise an event or command that the view can handle. So the view decides which UI action is associated with the command / event
eg. just
class SomeView { void HandleSomeCommandOrEvent() { this.Activate(); } }
Of course, how you do this is up to you, but I will probably try to execute routable commands.
Edit: you cannot βbindβ a simple event, since it is called from the viewmodel.
A simple event-based example is simply to add an event to the viewmodel and process it directly ... for example. imagine the next MainWindow with the ViewModel property
public partial class MainWindow : Window { MainWindowViewModel ViewModel { get; set; } public MainWindow() { InitializeComponent(); ViewModel = new MainWindowViewModel(); ViewModel.ShowMessage += ViewModel_ShowMessage; this.DataContext = ViewModel; } void ViewModel_ShowMessage(object sender, ShowMessageEventArgs e) { MessageBox.Show(e.Message, "Some caption", MessageBoxButton.OK); } }
Then ViewModel can just fire the event:
XAML will be:
<Button Command="{Binding ButtonClickCommand}">Click me!</Button>
Thus, the button invokes a command, which, in turn, fires an event that processes the view (MainWindow) and displays a message. Thus, the view / user interface decides on the course of action based on the type of event raised. Of course, it could be your timer that triggered the event.
You can always take a more attractive route, for example, some answers to this question ...
How to close ViewModel form?
but honestly, it depends on whether you really need it - a simple event works well - some people overly complicate things for the sake of elegance, but to the detriment of simplicity and performance!