Skip to content

Conversation

@Rosuavio
Copy link
Contributor

@Rosuavio Rosuavio commented Apr 23, 2021

Fixes #3311 Remove incorrect usages of DependencyProperty.UnsetValue and use it in values converters where appropriate.

In some places we are using DependencyProperty.UnsetValue where we are not supposed to.
DependencyProperty.UnsetValue is only supposed to be used as a returned value from IValueConverters that fail to convert there value. This pr removes it from where its not supposed to be used and uses it in value converters instead of throwing exceptions.

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

What is the new behavior?

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Pull Request has been submitted to the documentation repository instructions. Link:
  • Sample in sample app has been added / updated (for bug fixes / features)
  • New major technical changes in the toolkit have or will be added to the Wiki e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

Other information

@ghost
Copy link

ghost commented Apr 23, 2021

Thanks RosarioPulella for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

@ghost ghost requested review from Kyaa-dost, azchohfi and michael-hawker April 23, 2021 14:55
@Rosuavio
Copy link
Contributor Author

I am letting #3943 fix the instance in ColorPicker.

@Rosuavio
Copy link
Contributor Author

There are some locations where our usage of DependencyProperty.UnsetValue is questionable, this would be a good opportunity to check them.

https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/68888d2d7f0eba1b1f671a7ba1acc775ac0a46ef/Microsoft.Toolkit.Uwp.Input.GazeInteraction/GazeTargetItem.cs#L45-L55

@michael-hawker
Copy link
Member

@RosarioPulella the ReadLocalValue cases are all fine and expected. That's like the one case where we do want to be checking against UnsetValue. 🙂 (Appreciate you finding them all though!)

Basically ReadLocalValue gets the raw value from the runtime itself as opposed to just trying to get the value from the property and having it return null. So ReadLocalValue may also return null if the developer set the property value to null, but would instead return UnsetValue if it wasn't set at all.

That's why we should adhere to the contract in the other places with PropertyMetadata and IValueConverter to ensure that the rest of the system works as intended.

Since it looks like it's just the one update here for ClipToBounds (outside the incoming ColorPicker updates), would you want to add having the ValueConverters returns UnsetValue as part of this PR too for #3311? (I think we have some Unit Tests for the converters, if not we should, so that could be a starting point as well to ensure we're not breaking anything when we switch?)

@Rosuavio
Copy link
Contributor Author

would you want to add having the ValueConverters returns UnsetValue as part of this PR too for #3311?

Yep, I'll comb threw!

@Rosuavio Rosuavio marked this pull request as ready for review April 26, 2021 20:38
@Kyaa-dost Kyaa-dost added the bug 🐛 An unexpected issue that highlights incorrect behavior label Apr 26, 2021
@michael-hawker michael-hawker merged commit 26cd3f9 into CommunityToolkit:main May 3, 2021
@ghost ghost added the improvements ✨ label May 3, 2021
@michael-hawker michael-hawker added this to the 7.1 milestone May 3, 2021
@michael-hawker michael-hawker modified the milestones: 7.1, 7.0.2 May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐛 An unexpected issue that highlights incorrect behavior hotfix 🌶 improvements ✨ priority 🚩

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Clean-up] Make sure all Converters return UnsetValue

3 participants