質問

This is my first MVVM app, and I am wondering how to switch to another view after the user is done with the OpenFileDialog.

The changing view technique currently using is borrowed from here.

In other word, how to call :

private void ExecuteGridViewCommand()
{
    CurrentViewModel = MainViewModel._gridViewModel;
}

The problem rises since I couldn't track when the user clicks the Open button of the Dialog since the Dialog is not a XAML control.

    private static ViewModelBase _currentViewModel;
    public ViewModelBase CurrentViewModel
    {
        get { return _currentViewModel; }
        set
        {
            if (_currentViewModel != value)
            {
                _currentViewModel = value;
                OnPropertyChanged();
            }
        }
    }
役に立ちましたか?

解決

Somebody earlier sent an answer (deleted) that was inspiring (thanks) even though it didn't work out of the box, maybe due to instantiating a new instance of ViewModelLocator().

It was something like this:

private readonly MainViewModel _mainViewModel = (new ViewModelLocator().Main);
_mainViewModel.ExcuteGridView();

After tweaking, now I have this, and it works:

ViewModelLocator.Main.ExcuteGridView();

In order for this to work though, I had to declare the Main as static inside the ViewModelLocator:

 public static MainViewModel Main
    {
        get
        {
            return _main;
        }
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top