Q:

ReactiveUI ReactiveCommand with dynamic predicate

I am trying to find a way to change the predicate of a ReactiveUI ReactiveCommand during command's lifetime:
 public class Form1ViewModel
{
    public Form1ViewModel()
    {
        TestAction = () => Observable.Start(() => { MessageBox.Show("Initial step"); });
        TestCommand = ReactiveCommand.CreateFromObservable(TestAction);
        TestCommand.ThrownExceptions.Subscribe(ex => MessageBox.Show(string.Format("Something went wrong while executing test command: {0}", ex)));
        TestAction = () => Observable.Start(() => { MessageBox.Show("Another step"); });

    }
    public ReactiveCommand TestCommand { get; set; }
    public Func<IObservable<Unit>> TestAction { get; set; }
}

When executing command from the view binded to this viewmodel, it always gives "Initial step" message instead of "Another step".
Any ideas would be appreciated.

A:

You passed the current value of TestAction to CreateFromObservable and then changed the value of TestAction. That will never work.
You can try.
 public class Form1ViewModel
{
    public Form1ViewModel()
    {
        TestAction = () => Observable.Start(() => { MessageBox.Show("Initial step"); });
        TestCommand = ReactiveCommand.CreateFromObservable(()=>TestAction());
        TestCommand.ThrownExceptions.Subscribe(ex => MessageBox.Show(string.Format("Something went wrong while executing test command: {0}", ex)));
        TestAction = () => Observable.Start(() => { MessageBox.Show("Another step"); });

    }
    public ReactiveCommand TestCommand { get; set; }
    public Func<IObservable<Unit>> TestAction { get; set; }
}

