Ejemplo n.º 1
0
        /// <summary>
        /// Entry point for executing a command asynchronously and managing the display during the operation.
        /// </summary>
        /// <param name="command">The ReactiveCommand to execute asynchronously.</param>
        /// <param name="callbackAction">The action to perform when the command completes.</param>
        /// <param name="workingMessage">The message to display while the command is executing.</param>
        /// <param name="completedMessge">(Optional) The message to display when the command completes.</param>
        private void ExecuteAsyncCommand <T>(ReactiveCommand <T> command, Action <T> callbackAction, string workingMessage, string completedMessge = null)
        {
            //Update the UI to indicate an operation is in progress.
            Mouse.OverrideCursor     = Cursors.Wait;
            IsActionInProgress       = true;
            SelectedFeatureViewModel = new WaitViewModel(IsActionInProgress, workingMessage);
            CurrentStatusText        = workingMessage;

            //Execute the async command with the specifed callback delegate.
            CancellationToken token = new CancellationToken(false);

            command.ExecuteAsync().Subscribe(callbackAction, ex => HandleException(ex), () => OnCommandCompleted(completedMessge), token);
        }
Ejemplo n.º 2
0
        void SetupRx()
        {
            var countAsBehavior = Observable.Concat(
                Observable.Defer(() => Observable.Return(navigationStack.Count)),
                NavigationStack.CountChanged);

            NavigateBack = ReactiveCommand.CreateAsyncObservable(countAsBehavior.Select(x => x > 1), _ => {
                NavigationStack.RemoveAt(NavigationStack.Count - 1);
                return(Observable.Return(Unit.Default));
            });

            Navigate = new ReactiveCommand <INavigatableViewModel>(Observable.Return(true), x => {
                var vm = x as INavigatableViewModel;
                if (vm == null)
                {
                    throw new Exception("Navigate must be called on an INavigatableViewModel");
                }

                NavigationStack.Add(vm);
                return(Observable.Return <INavigatableViewModel>(vm));
            });
            NavigateToMainPage = new ReactiveCommand <INavigatableViewModel>(Observable.Return(true), x =>
            {
                var vm = x as INavigatableViewModel;
                if (vm == null)
                {
                    throw new Exception("Navigate must be called on an INavigatableViewModel");
                }
                NavigationStack.Clear();
                return(Observable.Return(vm));
            });

            NavigateAndReset = new ReactiveCommand <INavigatableViewModel>(Observable.Return(true), x => {
                NavigationStack.Clear();
                return(Navigate.ExecuteAsync(x));
                //return Observable.Return(x as INavigatableViewModel);
            });

            CurrentViewModel = Observable.Concat(
                Observable.Defer(() => Observable.Return(NavigationStack.LastOrDefault())),
                NavigationStack.Changed.Select(_ => NavigationStack.LastOrDefault()));
        }