Skip to content

How to subscribe to the properties of tree child nodes? #3715

Answered by anaisbetts
NicksGhost asked this question in Q&A
Discussion options

You must be logged in to vote

There's no super easy way to do this at the moment. The short version for a static list looks something like (coding via TextArea, forgive typos please!):

var anyCheckedChanged = Observable.Merge(
  Nodes.Select(node => 
    node.WhenAnyValue(x => x.IsChecked).Skip(1).Select(checked => (node, checked))));

(we skip 1 because we don't want to fire N initial states, though maybe you might want to do that!)

The problem is that you need to rebuild this Observable whenever any items in the list change. This is where DynamicData is a good solution, to create a projection of your IsChecked values. Another solution is building on our previous solution, something like:

var anyCheckedChange = listIt…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@NicksGhost
Comment options

@anaisbetts
Comment options

Answer selected by anaisbetts
Comment options

You must be logged in to vote
2 replies
@ChrisPulman
Comment options

@NicksGhost
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants