kwesolowski
kwesolowski

Reputation: 724

Propagating null within OneWayBind in ReactiveUI

I have pretty simple ReactiveObject ViewModel, where properties are ReactiveObjects.

In view I have following binding:

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

Is it possible to set Tooltip to null when CurrentEditor becomes null?

Upvotes: 1

Views: 524

Answers (1)

Gluck
Gluck

Reputation: 2962

This is the expected behavior as per the docs.

There may be a better way to achieve it, but at the very least you can use WhenAnyValue and bind it to both CurrentEditor and 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);

Upvotes: 1

Related Questions