protected IViewModel CreateViewModelByUsingDataContextOrConstructor()
{
var dataContext = TargetView.DataContext;
// It might be possible that a view model is already set, so use it if the datacontext is a view model
var dataContextAsIViewModel = dataContext as IViewModel;
if ((dataContextAsIViewModel != null) && (dataContextAsIViewModel.GetType() == ViewModelType))
{
return dataContextAsIViewModel;
}
return ConstructViewModelUsingArgumentOrDefaultConstructor(dataContext);
}