Skip to content

WhenAnyValue with null propogation, how to init and monitor for other values? #3770

Answered by sinatrocious
sinatrocious asked this question in Q&A
Discussion options

You must be logged in to vote

Found a workaround!

For null propagated property it's absolutely necessary to create an extra property to monitor only for value changes of that property and then use that extra property instead of null-forgiving operator. Then WhenAnyValue works for all scenarios.

To fix code from first post:

  1. Add extra property to parent (it can be anywhere, but makes the most sense to be there):
[ObservableAsProperty]
public string? ChildProperty { get; }
  1. Use 2 subscriptions:
// this subscription only monitors for child property value
// it will stop working as any WhenAnyValue with null-forgiving operator when parent in expression is null
// but we don't care, as we only need correct value when par…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sinatrocious
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant