예제 #1
0
        /// <inheritdoc />
        public IViewModel CreateViewModel(Type viewModelType, IViewModel parentVM, ViewModelOptions viewModelOptions)
        {
            lock (_viewModels)
            {
                IViewModel vm = (IViewModel)_container.Resolve(viewModelType);

                if (viewModelOptions == null)
                {
                    viewModelOptions = vm.DefaultViewModelOptions;
                }
                vm.SetViewModelOptions(viewModelOptions);
                var id = ++_lastID;
                _logger?.Log(_eventsSource, $"ViewModelCreated {viewModelType.Name}", LogRecordTypes.Debug);
                var vmInfo = new ViewModelInfo(vm)
                {
                    ID = id
                };

                if (!_viewModels.Any() && parentVM == null)
                {
                    RootViewModel = vmInfo;
                }
                else if (parentVM == null && RootViewModel != null)
                {
                    parentVM = RootViewModel.ViewModel;
                }

                if (parentVM != null && _viewModels.ContainsKey(parentVM))
                {
                    var parent = _viewModels[parentVM];
                    vmInfo.ParentViewModel = parent;
                    parent.ChildViewModels.Add(vmInfo);
                }

                _viewModels.TryAdd(vm, vmInfo);
                ViewModelCreated?.Invoke(this, vmInfo);

                return(vm);
            }
        }
예제 #2
0
 /// <summary>
 /// Creates a child ViewModel
 /// </summary>
 protected TResult CreateViewModel <TResult>(ViewModelOptions viewModelOptions) where TResult : IViewModel
 {
     return(_vmManager.CreateViewModel <TResult>(this, viewModelOptions));
 }
예제 #3
0
 /// <summary>
 /// Creates a child ViewModel
 /// </summary>
 protected IViewModel CreateViewModel(Type viewModelType, ViewModelOptions viewModelOptions)
 {
     return(_vmManager.CreateViewModel(viewModelType, this, viewModelOptions));
 }
예제 #4
0
 /// <summary>
 /// Set the <see cref="ViewModelOptions"/> property
 /// </summary>
 /// <param name="options"></param>
 public virtual void SetViewModelOptions(ViewModelOptions options)
 {
     ViewModelOptions = options;
 }
예제 #5
0
 /// <inheritdoc />
 public TResult CreateViewModel <TResult>(IViewModel parentVM, ViewModelOptions viewModelOptions) where TResult : IViewModel
 {
     return((TResult)CreateViewModel(typeof(TResult), parentVM, viewModelOptions));
 }