在ReactiveUI中的OneWayBind中传播null

时间:2015-08-09 10:29:56

标签: c# reactiveui

我有非常简单的ReactiveObject ViewModel,其中属性为ReactiveObject s。

在视图中我有以下绑定:

this.OneWayBind(ViewModel,
                 vm => vm.CurrentEditor.SelectedTreeViewItem.ItemTitle,
                 v => v.CurrentSelectionImage.ToolTip);

null变为CurrentEditor时,是否可以将工具提示设置为null

1 个答案:

答案 0 :(得分:1)

根据docs,这是预期的行为。

可能有更好的方法来实现它,但至少你可以使用WhenAnyValue并将它绑定到CurrentEditor CurrentEditor.SelectedTreeViewItem.ItemTitle:

ViewModel.WhenAnyValue(vm => vm.CurrentEditor,
                       vm => vm.CurrentEditor.SelectedTreeViewItem.ItemTitle,
                       (ce, title) => ce == null ? null : title)
         .BindTo(this, v => v.CurrentSelectionImage.ToolTip);