Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Null-coditional operators in bindings. #17731

Open
grokys opened this issue Dec 9, 2024 · 1 comment
Open

Proposal: Null-coditional operators in bindings. #17731

grokys opened this issue Dec 9, 2024 · 1 comment

Comments

@grokys
Copy link
Member

grokys commented Dec 9, 2024

Is your feature request related to a problem? Please describe.

When working with bindings, if the binding system detects that there is a null value somewhere along the binding path, it logs a warning:

 <TextBlock Text="{Binding Foo.Bar}"/>
[Binding]An error occurred binding 'Text' to 'Foo.Bar' at 'Foo': 'Value is null.' (TextBlock #14000148)

Often this warning is useful for diagnostic purposes, but at other times it is expected that the value of Foo may be null, which which case the warning is noise.

Describe the solution you'd like

The proposal is to add support for a null-conditional operator, similar to that of C# to the Avalonia binding system. The null-conditional operator would take the form ?.:

 <TextBlock Text="{Binding Foo?.Bar}"/>

When a binding path node is followed by the null-conditional operator, and the result of reading the value from the property specified by the node is null, no warning will be logged.

Describe alternatives you've considered

C# also has a null-conditional element accessor (?[]). This proposal does not suggest to add this operator immediately as it is my opinion that the operator would have much less utility than ?.. If there is seen to be need for it, then it can be added in future.

Additional context

No response

@grokys grokys self-assigned this Dec 9, 2024
@grokys
Copy link
Member Author

grokys commented Dec 9, 2024

Apologies - I didn't see this issue before opening which suggests the same thing: #17029

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant