Skip to content

Fixed issue in TypedBinding not being able to support nullable types properly#381

Merged
TheCodeTraveler merged 8 commits intoCommunityToolkit:mainfrom
jBijsterboschNL:main
Apr 11, 2025
Merged

Fixed issue in TypedBinding not being able to support nullable types properly#381
TheCodeTraveler merged 8 commits intoCommunityToolkit:mainfrom
jBijsterboschNL:main

Conversation

@jBijsterboschNL
Copy link
Copy Markdown
Contributor

@jBijsterboschNL jBijsterboschNL commented Apr 11, 2025

Description of Change

When using the TypedBinding with a nullable type, an InvalidOperationException("Unable to find target value") was throw incorrectly/unnecessary.

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description => a unit test perfectly shows an sample of this fix)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Additional information

Nullable types are now properly supported.

@TheCodeTraveler TheCodeTraveler added the breaking change Contains a breaking change requiring us to bump the Major Version number in the next release label Apr 11, 2025
Copy link
Copy Markdown
Collaborator

@TheCodeTraveler TheCodeTraveler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jBijsterboschNL!!

Just FYI - I updated the generic constraints to better implement this feature without using the Null Forgiving Operator (!).

This is modifies the API which is technically a breaking change, albeit, it should be a small impact with a relatively quick fix:

For example, this:

setter: static (vm, text) => vm.Text = text

becomes

setter: static (vm, text) => vm.Text = text ?? string.Empty

@TheCodeTraveler TheCodeTraveler merged commit 21f14ef into CommunityToolkit:main Apr 11, 2025
7 of 9 checks passed
@jBijsterboschNL
Copy link
Copy Markdown
Contributor Author

jBijsterboschNL commented Apr 13, 2025

@TheCodeTraveler at first I didn't want to make it a breaking change (had the same idea), but good call to do it like this! Thanks for the quick follow up and merging this thing. Any idea on when this could be released, are there any plans for a new release yet? Thanks in advance!

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

Labels

breaking change Contains a breaking change requiring us to bump the Major Version number in the next release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Set nullable BindableProperty to null throws Exception

2 participants