Question

Without wanting to bug sacha too much, does anyone know what the Cinch V2 way of closing a View from a ViewModel command?

Previously I have used a RelayCommand in the ViewModel base to accept the Escape keybinding command action and wired up a RequestClose event in the View code behind to do this.

Was it helpful?

Solution

Use CloseActivePopUpCommand.Execute(true) in the execute method to close a view.

I've included a short sample below.

[ExportViewModel("PickOperatorViewModel")]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class PickOperatorViewModel : ViewModelBase
{
  [ImportingConstructor]
  public PickOperatorViewModel()
  {
    PickOperaterCommand = new SimpleCommand<Object, Object>(CanExecutePickOperaterCommand, ExecutePickOperaterCommand);
  }

  public SimpleCommand<Object, Object> PickOperaterCommand { get; private set; }
  private void ExecutePickOperaterCommand(Object args)
  {
    CloseActivePopUpCommand.Execute(true);
  }

  private bool CanExecutePickOperaterCommand(Object args)
  {
    return true;
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top