-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
Description
First of all, thanks for this, it definitely helped me get my head around where I needed to go. Normally I'd make the changes and issue a PR, but in this case I was just grabbing some of the things you've done and rolling it my own way as well.
I had a quick suggestion on the IViewFor interface. It seems like you don't really need to have the ViewModel property in that interface. I simplified it to just -
public interface IViewFor<T> : IViewFor where T : IViewModel
{ }
Then you can change NavigationService.IntantiateView to this -
IViewFor<T> InstantiateView<T>(T viewModel) where T : class, IViewModel
{
// Figure out what type the view model is
var viewModelType = viewModel.GetType();
// look up what type of view it corresponds to
var viewType = _viewModelViewDictionary[viewModelType];
// instantiate it
var view = (IViewFor<T>)Activator.CreateInstance(viewType);
view.BindingContext = viewModel;
return view;
}
You're still getting the binding context in there, but now you don't have to go and add that property to every view.