我对C#有点新,并在https://www.tutorialspoint.com/mvvm/mvvm_hierarchies_and_navigation.htm
处理MVVM教程我遇到了MainWindowViewModel
的问题class MainWindowViewModel : BindableBase {
public MainWindowViewModel( ) {
NavCommand = new MyICommand<string>(OnNav);
}
private CustomerListViewModel custListViewModel = new CustomerListViewModel( );
private OrderViewModel orderViewModelModel = new OrderViewModel( );
private BindableBase _CurrentViewModel;
public BindableBase CurrentViewModel {
get { return _CurrentViewModel; }
set { SetProperty(ref _CurrentViewModel, value); }
}
public MyICommand<string> NavCommand { get; private set; }
private void OnNav(string destination) {
switch (destination) {
case "orders":
//CurrentViewModel = orderViewModelModel;
break;
case "customers":
default:
//CurrentViewModel = custListViewModel;
break;
}
}
}
我无法使用以上2行设置应用程序来设置CurrentViewModel取消注释。我得到了:
无法隐式转换类型&#39; MVVMHierarchiesDemo.ViewModel.OrderViewModel&#39;到&#39; MVVMHierarchiesDemo.BindableBase&#39;
无法隐式转换类型&#39; MVVMHierarchiesDemo.ViewModel.CustomerListViewModel&#39;到&#39; MVVMHierarchiesDemo.BindableBase&#39;
我确实在前面的(tutorualspoint)教程中发现了一个拼写错误/错误,但在层次结构教程中没有看到任何错误。
我有没有看到这个例子的问题?
答案 0 :(得分:0)
我不知道为什么,但你可以试试。
class OrderViewModel :BindableBase
{
}
class OrderViewModel :BindableBase
{
}
答案 1 :(得分:0)
您的$ ls -al /dev | grep fd
dr-xr-xr-x 1 root wheel 0 Jan 23 20:42 fd/
$ stat /dev/fd/4 # same result with -L flag
stat: /dev/fd/4: stat: Bad file descriptor
属性属于CurrentViewModel
类型,因此您要为其指定的任何对象应为BindableBase
或从中派生。
这就是为什么您必须将BindableBase
添加到您的课程: BindableBase
和CustomerListViewModel
中:
OrderViewModel