/// <summary>
 /// A utility method that will pipe an Observable to an ICommand (i.e.
 /// it will first call its CanExecute with the provided value, then if
 /// the command can be executed, Execute() will be called)
 /// </summary>
 /// <param name="command">The command to be executed.</param>
 /// <returns>An object that when disposes, disconnects the Observable
 /// from the command.</returns>
 public static IDisposable InvokeCommand <T, TResult>(this IObservable <T> This, IReactiveCommand <TResult> command)
 {
     return(This.Throttle(x => command.CanExecuteObservable.StartWith(command.CanExecute(x)).Where(b => b))
            .Select(x => command.ExecuteAsync(x).Catch(Observable.Empty <TResult>()))
            .Switch()
            .Subscribe());
 }
 public static void ExecuteIfCan(this IReactiveCommand @this, object o)
 {
     if (@this.CanExecute(o))
     {
         @this.Execute(o);
     }
 }
 /// <summary>
 /// A utility method that will pipe an Observable to an ICommand (i.e.
 /// it will first call its CanExecute with the provided value, then if
 /// the command can be executed, Execute() will be called)
 /// </summary>
 /// <param name="command">The command to be executed.</param>
 /// <returns>An object that when disposes, disconnects the Observable
 /// from the command.</returns>
 public static IDisposable InvokeCommand <T>(this IObservable <T> This, IReactiveCommand command)
 {
     return(This.Throttle(x => command.CanExecuteObservable.StartWith(command.CanExecute(x)).Where(b => b))
            .Subscribe(x => {
         command.Execute(x);
     }));
 }
Exemple #4
0
        private void SongDoubleClick(object sender, MouseButtonEventArgs e)
        {
            IReactiveCommand command = this.ViewModel.DefaultPlaybackCommand;

            if (e.LeftButton == MouseButtonState.Pressed && command.CanExecute(null))
            {
                command.Execute(null);
            }
        }
Exemple #5
0
        private void SongKeyPressed(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                IReactiveCommand command = this.ViewModel.DefaultPlaybackCommand;

                if (command.CanExecute(null))
                {
                    command.Execute(null);
                }

                e.Handled = true;
            }
        }