예제 #1
0
        protected ViewModelBaseWrapper GetViewModel(ViewModelConnection item)
        {
            Type type = item.ViewModelType;
            ViewModelBaseWrapper viewModel = (ViewModelBaseWrapper)_iocManager.Resolve(item.ViewModelType);

            return(viewModel);
        }
예제 #2
0
        public void RegisterViewModel <VM, V>()
            where VM : ViewModelBase
            where V : ContentControl
        {
            var item = new ViewModelConnection();

            item.Set <VM, V>();
            _views.Add(item);

            _iocManager.RegisterType <VM>();
        }
예제 #3
0
        public void OpenViewBlocking(Type VM, ContentControl control = null, Parameter parameter = null)
        {
            if (control != null)
            {
                if (control.DataContext as ViewModelBaseWrapper != null)
                {
                    (control.DataContext as ViewModelBaseWrapper).NavigatedFrom();
                }
            }

            // Get item for passed viewModel type
            ViewModelConnection item = _views.FirstOrDefault(x => x.ViewModelType == VM);

            if (item == null)
            {
                throw new Exception("View not registered.");
            }

            ContentControl view = GetView(item);

            ViewModelBaseWrapper viewModel = view.DataContext as ViewModelBaseWrapper;

            if (viewModel == null)
            {
                viewModel = GetViewModel(item);
            }

            if (control == null)
            {
                view.DataContext = viewModel;
                _content.Content = view;
            }
            else
            {
                view.DataContext = viewModel;
                control.Content  = view;
            }

            viewModel.Parameters = parameter;
            viewModel.NavigatedTo();
        }
예제 #4
0
 protected ContentControl GetView(ViewModelConnection item) => Activator.CreateInstance(item.ViewType) as ContentControl;