Example #1
0
        public bool?ShowDialogView(IViewModelBase viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            var result = default(bool?);

            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.Invoke(() => result = ShowDialogView(viewModel));
            }
            else
            {
                var viewType = _viewModel2View.Single(item => item.ViewModel == viewModel.GetType()).View;
                try
                {
                    var view = (Window)Activator.CreateInstance(viewType);
                    view.DataContext = viewModel;

                    view.Closed += (sender, e) => viewModel.Dispose();

                    result = view.ShowDialog();
                }
                catch (Exception ex)
                {
                    ShowMessage(ex.ToString(), "Erro", MsgBoxButton.OK, MsgBoxIcon.Error);
                }
            }

            return(result);
        }
 /// <summary>Constructor</summary>
 /// <param name="viewModel">The model (must implement IViewModelBase) that will use ViewModelStateHelper</param>
 public ViewModelStateHelper(IViewModelBase viewModel)
 {
     if (viewModel == null)
     {
         throw new ArgumentNullException();
     }
     _viewModelName = viewModel.GetType().Name;
 }
        public void NavigateToViewModel(
            IViewModelBase viewModelBase,
            bool clearBackStack,
            IReadOnlyList <NavigationParameterModel>?parameters)
        {
            var type = _viewLocator.GetTargetType(viewModelBase.GetType(), ViewType.Activity);

            StartActivityImpl(type, clearBackStack, parameters);
        }
        public virtual object GetView(IViewModelBase viewModel, ViewType viewType)
        {
            var targetType = GetTargetType(viewModel.GetType(), viewType);
            var view       = Activator.CreateInstance(targetType);

            if (view is IBindable bindable)
            {
                bindable.SetDataContext(viewModel);
            }

            return(view);
        }
Example #5
0
        private Page GetView(IViewModelBase viewmodel)
        {
            var attrib = viewmodel.GetType().GetCustomAttributes(typeof(ViewTypeAttribute), false).FirstOrDefault() as ViewTypeAttribute;

            if (attrib != null && attrib.PageType != null)
            {
                var page = (Page)Activator.CreateInstance(attrib.PageType);
                FillViewModel(viewmodel, page);
                page.DataContext = viewmodel;
                return(page);
            }

            return(null);
        }
Example #6
0
        public void ShowView(IViewModelBase viewModel, Action closeAction = null)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.Invoke(() => ShowView(viewModel, closeAction));
                return;
            }

            try
            {
                var viewType = _viewModel2View.Single(item => item.ViewModel == viewModel.GetType()).View;
                var view     = (Window)Activator.CreateInstance(viewType);
                view.DataContext = viewModel;

                view.Closed += (sender, args) =>
                {
                    if (closeAction != null)
                    {
                        closeAction.Invoke();
                    }

                    viewModel.Dispose();
                };

                view.Show();
            }
            catch (Exception ex)
            {
                ShowMessage(ex.ToString(), "Erro", MsgBoxButton.OK, MsgBoxIcon.Error);
            }
        }