/// <summary> /// Event handler for the DataContextChanged event. /// Registers an event handler for the ViewModel's CloseRequest event. /// </summary> /// <param name="sender">Sender of the event (this class itself).</param> /// <param name="e">Event args of the event.</param> private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { _viewModel = e.NewValue as SimpleViewModel; if (_viewModel != null) { _viewModel.CloseRequest += ViewModelCloseRequest; } }