public void InitializeNextViewModel(IHasViewModel current, IHasViewModel next, string identifier)
 {
     var nextVmTypeName = next.GetType().FullName.Replace("Controller", "ViewModel");
     var nextVm = Construct(nextVmTypeName);
     next.VM = (INotifyPropertyChanged)nextVm;
     SetPredecessor(current, next);
     SetIdentifier(next.VM, identifier);
 }
Exemplo n.º 2
0
        public BaseViewModel Load(IHasViewModel viewVm)
        {
            BaseViewModel viewModel = (from vm in ViewModels
                                       where vm.Metadata.Name == viewVm.ViewModelName
                                       select vm.Value).FirstOrDefault();

            if (viewModel == null)
            {
                throw new ArgumentException("Invalid name: " + viewVm.ViewModelName);
            }

            BaseViewModel result;

            if (!_viewsAndViewModels.ContainsKey(viewVm.ViewModelName))
            {
                InitViewModelOperation(viewVm, viewModel);
                viewVm.IsViewModelLoaded = true;
                _viewsAndViewModels[viewVm.ViewModelName] = new Dictionary <IHasViewModel, BaseViewModel> {
                    { viewVm, viewModel }
                };
            }

            if (viewVm.IsViewModelLoaded)
            {
                result = _viewsAndViewModels[viewVm.ViewModelName][viewVm];
            }
            else
            {
                var newViewModel = (BaseViewModel)Activator.CreateInstance(viewModel.GetType());
                InitViewModelOperation(viewVm, newViewModel);
                viewVm.IsViewModelLoaded = true;
                _viewsAndViewModels[viewVm.ViewModelName].Add(viewVm, newViewModel);
                result = newViewModel;
            }
            result.ViewModelDisposed += ViewModelDisposed;
            return(result);
        }
Exemplo n.º 3
0
        private void InitViewModelOperation(IHasViewModel viewVm, BaseViewModel viewModel)
        {
            BaseOperationViewModel vm;

            if (viewVm.ExtendedData != null && (vm = viewModel as BaseOperationViewModel) != null)
            {
                object obj;
                if (viewVm.ExtendedData.TryGetValue("OperationName", out obj))
                {
                    var operationName = obj as string;
                    if (!string.IsNullOrEmpty(operationName))
                    {
                        try
                        {
                            vm.Operation = App.Container.GetExportedValue <IDebuggerOperation>(operationName);
                        }
                        catch (ImportCardinalityMismatchException e)
                        {
                            App.Container.GetExport <IDialogService>().Value.ShowDialog(e.Message);
                        }
                    }
                }
            }
        }
 static void SetPredecessor(IHasViewModel current, IHasViewModel next)
 {
     var predecessorProperty = next.VM.GetType().GetProperty("Predecessor");
     predecessorProperty.SetValue(next.VM, current.VM);
 }