I'm trying to implement MVVM navigation in my MainWindow after login, before that after click on 'Login' button i've to call MainWindow.xaml to display and after that i used to do navigation in my Mainwindow based on menu/ribbon selection.
Below is the implementation i've done so far:
On 'Login' button command:
private void Entry(object parameter)
{
IMainWindowViewModel viewM = new MainWindowViewModel();
ViewBinder<IMainWindowView> main = new ViewBinder<IMainWindowView>(viewM);
var view = main.View;
}
MainWindowViewModel:
public class MainWindowViewModel:ViewModel<IMainWindowView>, IMainWindowViewModel
{
public int EmpID
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public string EmpName
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public void GetEmployees()
{
throw new NotImplementedException();
}
public object DataContext
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public MainWindowViewModel(IMainWindowView view)
: base(view)
{ }
}
IMainWindowViewModel:
public interface IMainWindowViewModel:IMainWindowView
{
int EmpID { get; set; }
string EmpName { get; set; }
void GetEmployees();
}
IMainWindowView:
public interface IMainWindowView:IView
{
}
ViewBinder:
public class ViewBinder<T> where T : IView
{
private T currentView;
public IView View
{
get
{
var viewModel = currentView.GetViewModel();
return (IView)viewModel.View;
}
}
public ViewBinder(T targetView)
{
this.currentView = targetView;
}
}
But While run this app it's showing error message like below: 'System.Waf.Applications.ViewModel' does not contain a constructor that takes 0 arguments D:\MajorApps\SampleApp\MajorApps.Application\ViewModels\MainWindowViewModel.cs
Can anyone help me this out what i missed/wrong.
Thanks @nag