的ResourceDictionary:
<Page DataContext="{Binding Source={StaticResource Construction}, Path=AddEngineerViewModel}"/>
addEngineerView.xaml
public class ConstructionLocator
{
private static IDialogServices _dialog = new DialogServices();
private static IAddEngineerDataService _addEngineerDataServices = new AddEngineerDataServices(new AddEngineerData());
private static AddEngineerViewModel _addEngineerViewModel = new AddEngineerViewModel(_addEngineerDataServices, _dialog);
private static ViewEmployeeViewModel _viewEmployeeViewModel = new ViewEmployeeViewModel(_addEngineerDataServices, _dialog);
public static AddEngineerViewModel AddEngineerViewModel
{
get { return _addEngineerViewModel; }
}
public static ViewEmployeeViewModel ViewEmployeeViewModel
{
get { return _viewEmployeeViewModel; }
}
}
定位器:
public class AddEngineerViewModel:BindableBase
{
IAddEngineerDataService _engineerDataService;
IDialogServices _dialog;
public AddEngineerViewModel(IAddEngineerDataService AddEngineerDataService,IDialogServices Dialog)
{
_engineerDataService = AddEngineerDataService;
_dialog = Dialog;
LoadCommand();
}
private AddEngineerModel _addEngineer;
public AddEngineerModel AddEngineer
{
get { return _addEngineer; }
set
{
_addEngineer = value;
RaisePropertyChanged("AddEngineer");
}
}
public ICommand AddEngineerCommand { get; set; }
public ICommand ViewEngineerCommand { get; set; }
private void LoadCommand()
{
AddEngineerCommand = new CustomCommand(Add, CanAdd);
ViewEngineerCommand = new CustomCommand(Views, CanView);
}
private void Views(object obj)
{
_dialog.ShowDialog();
}
private bool CanView(object obj)
{
return true;
}
private bool CanAdd(object obj)
{
return true;
}
private void Add(object obj)
{
_engineerDataService.Add_Engineer_Details(_addEngineer);
}
}
视图模型:
{{1}}
当导航到按钮上的视图时,单击它会显示类型初始值设定项在addengineerviewmodel静态属性的定位器文件中引发异常。以上是我的定位器和视图模型。会有什么问题?