public void Wrap(IViewModel viewModel, IDataContext context = null)
        {
            EnsureNotDisposed();
            Should.NotBeNull(viewModel, nameof(viewModel));
            lock (_locker)
            {
                if (_viewModel != null)
                {
                    throw ExceptionManager.ObjectInitialized("ViewModel", viewModel);
                }
                _viewModel = (TViewModel)viewModel;
            }
            //It indicates that wrapper is responsible for the view model state.
            _viewModel.Settings.Metadata.AddOrUpdate(ViewModelConstants.StateNotNeeded, true);
            ViewModel.PropertyChanged += ViewModelOnPropertyChanged;
            var closeableViewModel = ViewModel as ICloseableViewModel;

            if (closeableViewModel == null)
            {
                CloseCommand = RelayCommandBase.FromAsyncHandler <object>(CloseAsync, false);
            }
            else
            {
                closeableViewModel.Closing += ViewModelOnClosing;
                closeableViewModel.Closed  += ViewModelOnClosed;
            }
            ViewModel.Subscribe(this);
            this.Subscribe(_viewModel);
            OnWrapped(context);
            InvalidateProperties();
        }
 public CollectionBindingViewModel(IMessagePresenter messagePresenter)
 {
     Should.NotBeNull(messagePresenter, nameof(messagePresenter));
     _messagePresenter = messagePresenter;
     AddCommand        = new RelayCommand(Add);
     RemoveCommand     = RelayCommandBase.FromAsyncHandler <CollectionItemModel>(Remove, CanRemove, this);
 }
        public MainViewModel(IToastPresenter toastPresenter)
        {
            Should.NotBeNull(toastPresenter, "toastPresenter");
            _toastPresenter = toastPresenter;
            Items           = new[]
            {
                Tuple.Create("Action bar (Dynamic tabs)", new ViewModelCommandParameter(typeof(TabViewModel))),
                Tuple.Create("Action bar (Static tabs)", new ViewModelCommandParameter(typeof(StaticTabViewModel))),
                Tuple.Create("Context action bar", new ViewModelCommandParameter(typeof(ContextActionBarViewModel))),
                Tuple.Create("Tab host (Dynamic tabs)", new ViewModelCommandParameter(typeof(TabViewModel), Constants.TabHostView)),
                Tuple.Create("Action bar (Dynamic menu)", new ViewModelCommandParameter(typeof(MenuViewModel))),
                Tuple.Create("Toolbar view", new ViewModelCommandParameter(typeof(ToolbarViewModel))),
                Tuple.Create("Popup menu", new ViewModelCommandParameter(typeof(MenuViewModel), Constants.PopupMenuView)),
                Tuple.Create("Back stack fragment", new ViewModelCommandParameter(typeof(BackStackFragmetViewModel), Constants.PopupMenuView)),
                Tuple.Create("ItemsSource with DataTemplateSelector", new ViewModelCommandParameter(typeof(ListDataTemplateViewModel))),
                Tuple.Create("RecyclerView + CardView", new ViewModelCommandParameter(typeof(TabViewModel), Constants.CardRecyclerView)),
                Tuple.Create("Preference", new ViewModelCommandParameter(typeof(PreferenceViewModel))),
                Tuple.Create("Preference headers", new ViewModelCommandParameter(typeof(PreferenceViewModel), Constants.PreferenceHeaderView)),
#if APPCOMPAT
                Tuple.Create("View pager (AppCompat)", new ViewModelCommandParameter(typeof(TabViewModel), Constants.ViewPagerView)),
                Tuple.Create("Drawer layout (AppCompat)", new ViewModelCommandParameter(typeof(DrawerViewModel))),
                Tuple.Create("Snackbar (Design)", new ViewModelCommandParameter(typeof(SnackbarViewModel))),
                Tuple.Create("Tab layout (Design)", new ViewModelCommandParameter(typeof(TabViewModel), Constants.TabLayoutView)),
                Tuple.Create("Navigation view (Design)", new ViewModelCommandParameter(typeof(NavigationViewModel)))
#endif
            };
            ShowCommand = RelayCommandBase.FromAsyncHandler <ViewModelCommandParameter>(Show);
        }
        public MainViewModel(IViewModelPresenter viewModelPresenter)
        {
            Should.NotBeNull(viewModelPresenter, "viewModelPresenter");
            viewModelPresenter.DynamicPresenters.Add(new DynamicMultiViewModelPresenter(this));

            OpenProductsCommand = RelayCommandBase.FromAsyncHandler(OpenProducts);
            OpenOrdersCommand   = RelayCommandBase.FromAsyncHandler(OpenOrders);
        }
 protected override RelayCommandBase CreateCommand(Action <object> execute, Func <object, bool> canExecute = null,
                                                   params object[] items)
 {
     return((RelayCommandBase)RelayCommandBase.FromAsyncHandler(o =>
     {
         execute(o);
         return Empty.Task;
     }, canExecute, true, items));
 }
        public UserWorkspaceViewModel(IUserRepository userRepository, IMessagePresenter messagePresenter)
        {
            Should.NotBeNull(userRepository, nameof(userRepository));
            Should.NotBeNull(messagePresenter, nameof(messagePresenter));
            _userRepository   = userRepository;
            _messagePresenter = messagePresenter;

            AddUserCommand    = new RelayCommand(AddUser, CanAddUser, this);
            RemoveUserCommand = RelayCommandBase.FromAsyncHandler(RemoveUser, CanRemoveUser, this);
        }
 public MainViewModel()
 {
     Items = new[]
     {
         Tuple.Create("Tabs", new ViewModelCommandParameter(typeof(TabViewModel))),
         Tuple.Create("Tabs (ItemTemplate)", new ViewModelCommandParameter(typeof(TabViewModel), Constants.TabViewItemTeplate)),
         Tuple.Create("View collection manager", new ViewModelCommandParameter(typeof(TabViewModel), Constants.CollectionViewManager)),
         Tuple.Create("Content binding", new ViewModelCommandParameter(typeof(ContentViewModel))),
         Tuple.Create("Content binding (View content manager)", new ViewModelCommandParameter(typeof(ContentViewModel), Constants.ContentFormContentManager)),
         Tuple.Create("Tree view binding", new ViewModelCommandParameter(typeof(TreeViewBindingViewModel), Constants.ContentFormContentManager))
     };
     ShowCommand = RelayCommandBase.FromAsyncHandler <ViewModelCommandParameter>(Show);
 }
        public ProductWorkspaceViewModel(IRepository repository, IMessagePresenter messagePresenter,
                                         IToastPresenter toastPresenter)
        {
            Should.NotBeNull(repository, "repository");
            Should.NotBeNull(messagePresenter, "messagePresenter");
            Should.NotBeNull(toastPresenter, "toastPresenter");
            _repository         = repository;
            _messagePresenter   = messagePresenter;
            _toastPresenter     = toastPresenter;
            _trackingCollection = new TrackingCollection(new CompositeEqualityComparer().AddComparer(ProductModel.KeyComparer));

            SaveChangesCommand   = RelayCommandBase.FromAsyncHandler(SaveChanges, CanSaveChanges, this);
            AddProductCommand    = RelayCommandBase.FromAsyncHandler(AddProduct);
            EditProductCommand   = RelayCommandBase.FromAsyncHandler <ProductModel>(EditProduct, CanEditProduct, this);
            RemoveProductCommand = RelayCommandBase.FromAsyncHandler <ProductModel>(RemoveProduct, CanRemoveProduct, this);
            DisplayName          = UiResources.ProductWorkspaceName;
        }
        public MainViewModel(IViewModelPresenter viewModelPresenter, IToastPresenter toastPresenter, IMessagePresenter messagePresenter)
        {
            Should.NotBeNull(viewModelPresenter, "viewModelPresenter");
            Should.NotBeNull(toastPresenter, "toastPresenter");
            Should.NotBeNull(messagePresenter, "messagePresenter");
            _viewModelPresenter      = viewModelPresenter;
            _toastPresenter          = toastPresenter;
            _messagePresenter        = messagePresenter;
            ShowFirstWindowCommand   = RelayCommandBase.FromAsyncHandler(ShowFirstWindow);
            ShowSecondWindowCommand  = RelayCommandBase.FromAsyncHandler(ShowSecondWindow);
            ShowFirstTabCommand      = RelayCommandBase.FromAsyncHandler(ShowFirstTab);
            ShowSecondTabCommand     = RelayCommandBase.FromAsyncHandler(ShowSecondTab);
            ShowFirstPageCommand     = RelayCommandBase.FromAsyncHandler(ShowFirstPage);
            ShowSecondPageCommand    = RelayCommandBase.FromAsyncHandler(ShowSecondPage);
            ShowBackStackPageCommand = RelayCommandBase.FromAsyncHandler(ShowBackStackPage);

            //NOTE The DynamicMultiViewModelPresenter allows to use the current view model as presenter.
            _presenter = new DynamicMultiViewModelPresenter(this);
            viewModelPresenter.DynamicPresenters.Add(_presenter);
        }
Ejemplo n.º 10
0
        public virtual void TaskCmdShouldNotBeExecuteMultipleTimes()
        {
            bool isInvoked = false;
            var  tcs       = new TaskCompletionSource <object>();
            var  command   = RelayCommandBase.FromAsyncHandler(() =>
            {
                isInvoked = true;
                return(tcs.Task);
            }, null, false);

            command.Execute(null);
            isInvoked.ShouldBeTrue();

            isInvoked = false;
            command.Execute(null);
            isInvoked.ShouldBeFalse();

            isInvoked = false;
            tcs.SetResult(null);
            command.Execute(null);
            isInvoked.ShouldBeTrue();
        }
Ejemplo n.º 11
0
 protected CloseableViewModel()
 {
     _closeCommand = RelayCommandBase.FromAsyncHandler <object>(ExecuteCloseAsync, CanCloseInternal, false, this);
 }
Ejemplo n.º 12
0
 public EditorWrapperViewModel()
 {
     ApplyCommand = RelayCommandBase.FromAsyncHandler <object>(Apply, CanApply, false, this);
 }
 public BackStackViewModel()
 {
     Depth           = 1;
     NavigateCommand = RelayCommandBase.FromAsyncHandler(Navigate);
     NavigateClearBackStackCommand = RelayCommandBase.FromAsyncHandler(NavigateClearBackStack);
 }
Ejemplo n.º 14
0
 public EditorWrapperVm()
 {
     SaveCommand = RelayCommandBase.FromAsyncHandler <object>(SaveAsync, CanSave, false, this);
 }
Ejemplo n.º 15
0
 public MainViewModel()
 {
     ShowAnnotationCommand = RelayCommandBase.FromAsyncHandler(ShowAnnotation);
     ShowUserEditorCommand = RelayCommandBase.FromAsyncHandler(ShowUserEditor);
 }