关闭OpenFileDialog时如何更改视图? [英] How to Change View when OpenFileDialog is Closed?
问题描述
这是我的第一个MVVM应用程序,我想知道在用户使用OpenFileDialog
完成操作后如何切换到另一个视图.
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;
}
由于对话框不是XAML控件,因此我无法跟踪用户单击对话框的打开"按钮时出现的问题.
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();
}
}
}
推荐答案
早些时候,有人发送了(已删除)一个令人鼓舞(谢谢)的答案,即使该方法开箱即用,也可能是由于实例化了一个新实例的ViewModelLocator().
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().
是这样的:
private readonly MainViewModel _mainViewModel = (new ViewModelLocator().Main);
_mainViewModel.ExcuteGridView();
调整后,现在我有了它,它可以正常工作:
After tweaking, now I have this, and it works:
ViewModelLocator.Main.ExcuteGridView();
为了使它起作用,我不得不在ViewModelLocator内部将Main声明为静态的:
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;
}
}
这篇关于关闭OpenFileDialog时如何更改视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!