1
votes

I have a simple view with a checkbox and a viewModel with a [Reactive] bool property.

I would like a change to the checkbox on the UI to propagate to the viewModel property, but I would also like to have the UI checkbox state get updated when the viewModel property is updated by external factors.

I assumed that a two way binding would do this

this.Bind(ViewModel, viewModel => viewModel.DepthLabel, view => view._depthLabel.IsChecked) .DisposeWith(disposable);

...but the UI is not responding when the field property changes from external factors.

What can I do to get the UI to update? If this is not what two-way bind is meant for, when should it be used?

1

1 Answers

1
votes

What can I do to get the UI to update?

Make sure that the DepthLabel source property is set on the dispatcher thread.

For example, in the following sample code, calling ObserveOnDispatcher() is required for the CheckBox in the view to update:

public class ViewModel : ReactiveObject
{
    [Reactive]
    public bool DepthLabel { get; set; }

    public ViewModel()
    {
        Observable.Timer(TimeSpan.FromSeconds(2))
           .ObserveOnDispatcher()
           .Subscribe(_ => DepthLabel = true);
    }
}