繁体   English   中英

ReactiveUI TwoWay绑定复选框

[英]ReactiveUI TwoWay binding a checkbox

我有一个带有复选框的简单视图和一个具有[Reactive] bool属性的viewModel。

我希望对UI上的复选框进行更改以传播到viewModel属性,但是当viewModel属性由外部因素更新时,我也希望UI复选框状态得到更新。

我认为双向绑定可以做到这一点

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

...但是当字段属性因外部因素而变化时,UI没有响应。

我该怎么做才能更新用户界面? 如果这不是双向绑定的意思,那么什么时候应使用它?

我该怎么做才能更新用户界面?

确保在调度程序线程上设置了DepthLabel source属性。

例如,在以下示例代码中,要更新视图中的CheckBox ,需要调用ObserveOnDispatcher()

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM