Skip to content

Conversation

@robloo
Copy link
Contributor

@robloo robloo commented Apr 16, 2021

Fixes #3940, Relates to #3311

  • I was not able to reproduce the reported crashes; however, this fixes the bug in code.
    • It is so far unclear how the crash might occur. The observable collection was being properly set in the constructor and should be called immediately before any default value (of the incorrect type) is used.
  • Other property values were updated to stop using UnsetValue default
  • Converters no longer throw exceptions and return UnsetValue when conversion fails
  • ColorPicker and ColorSpectrum now derive from the WinUI equivalent controls

Anyone customizing the Spectrum shape or components directly in C# will need to switch to Microsoft.UI.Xaml namespace This is a breaking change in code only - XAML will work unchanged.

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Refactoring (no functional changes, no api changes)

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 16, 2021

Thanks robloo 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, Rosuavio, azchohfi and michael-hawker April 16, 2021 18:37
@ghost ghost added the bug 🐛 An unexpected issue that highlights incorrect behavior label Apr 16, 2021
@ghost
Copy link

ghost commented Apr 16, 2021

Hello @Kyaa-dost!

Because this pull request has the auto merge :zap: label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

Do note that I've been instructed to only help merge pull requests of this repository that have been opened for at least 8 hours, a condition that will be fulfilled in about 6 hours 34 minutes. No worries though, I will be back when the time is right! 😉

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@Kyaa-dost
Copy link
Contributor

@msftbot Merge when @michael-hawker approves the PR

@ghost
Copy link

ghost commented Apr 16, 2021

Hello @Kyaa-dost!

Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:

If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you".

typeof(ObservableCollection<Windows.UI.Color>),
typeof(ColorPicker),
new PropertyMetadata(Windows.UI.Color.FromArgb(0x00, 0x00, 0x00, 0x00)));
new PropertyMetadata(DependencyProperty.UnsetValue));
Copy link
Member

Choose a reason for hiding this comment

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

We should never be using UnsetValue here, this should be always be null, if not a method. We should only use UnsetValue for value converters (bug #3311).

See docs for PropertyMetadata and UnsetValue both call this out.

Can you fix this here an in the other places as well? Thanks!

Copy link
Contributor Author

@robloo robloo Apr 22, 2021

Choose a reason for hiding this comment

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

@michael-hawker Ok, I will update. This was my misunderstanding. It would make sense that the property system supported this case (using default(T) as needed) but if it doesn't, it doesn't.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, no worries. Sorry we missed it in the initial PR. It's extra confusing because it's the opposite guidance for the Value Converters. We just haven't had a chance to go fix those yet with all the other work we did for 7.0. Thanks a bunch for working through the fix on the issue thread with the original reporter! 🦙❤

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed some other occurrences of UnsetValue doing a quick search. Here is an example:

https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/68888d2d7f0eba1b1f671a7ba1acc775ac0a46ef/Microsoft.Toolkit.Uwp.UI/Extensions/UIElementExtensions.cs#L19-L23

I think the code base needs to be audited for this situation a bit more.

Copy link
Contributor Author

@robloo robloo Apr 23, 2021

Choose a reason for hiding this comment

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

I've made the changes and updated the converters I added to return UnsetValue instead of throwing exceptions. I also removed the NotImplementedException from ConvertBack() it wasn't entirely clear if that should change per the docs.

I still can't believe it isn't supported in registration like this. DependencyObject.ReadLocalValue may return UnsetValue. ClearValue() uses it I think? I would also expect the default PropertyMetadata to use UnsetValue instead of null. Oh well, it's good to be aware of this.

@ghost
Copy link

ghost commented Apr 23, 2021

This PR has been marked as "needs attention 👋" and awaiting a response from the team.

@ghost ghost removed the auto merge ⚡ label Apr 23, 2021
@robloo
Copy link
Contributor Author

robloo commented Apr 23, 2021

I also switched to the WinUI ColorSpectrum and hit a roadblock. The ColorPicker itself forwards the ColorSpectrumComponents and ColorSpectrumShape properties directly to the internal spectrum. I can't have the ColorPicker using Windows.UI.Xaml enum values but the internal ColorSpectrum using Microsoft.UI.Xaml. Bottom line I need to switch the ColorPicker itself to derive from the WinUI ColorPicker as well.

Then we run into microsoft/microsoft-ui-xaml#3502 which normally requires the following line of code

this.DefaultStyleResourceUri = new System.Uri("ms-appx:///Themes/Generic.xaml"); switched to
this.DefaultStyleResourceUri = new System.Uri("ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls.Input/Themes/Generic.xaml"); for the toolkit.

I am unsure if this is safe to do in a library released to Nuget.

@Rosuavio Rosuavio mentioned this pull request Apr 23, 2021
8 tasks
@michael-hawker
Copy link
Member

@azchohfi did you have to update this for the WinUI changes since those all inherit now?

@robloo is the concern about it functioning or just changing things in a minor released version? I believe the WUX and MUX API surfaces are similar, so if we're functionally equivalent, I don't see a large problem with moving things forward?

@ghost ghost removed the needs attention 👋 label Apr 23, 2021
@robloo
Copy link
Contributor Author

robloo commented Apr 24, 2021

@robloo is the concern about it functioning or just changing things in a minor released version?

I'm concerned about it functioning. I'm not sure how Uri-based resource lookup works with a nuget library packaged with an app. In other words: I'm not sure how resource lookup works internally in this case with WinUI-styles, within the UWP toolkit added as a nuget to an app. Will everything still be packaged and appear normally with ms-appx?.

For the minor-breaking change I also wasn't thinking it was a concern. If anyone customizes things that will likely do it in XAML anyway. I considered the breaking change ok but made sure to flag it.

@michael-hawker
Copy link
Member

Wondering if we want to split the Unset fix from the move from WUX to MUX. Basically we can ship the Unset change in a 7.0.2 and leave the switch to the WinUI base control for 7.1? Maybe they'll fix the WinUI bug in 2.6 as we'll be updating for 7.1?

@robloo thoughts?

@robloo
Copy link
Contributor Author

robloo commented Apr 30, 2021

Wondering if we want to split the Unset fix from the move from WUX to MUX. Basically we can ship the Unset change in a 7.0.2 and leave the switch to the WinUI base control for 7.1? Maybe they'll fix the WinUI bug in 2.6 as we'll be updating for 7.1?

@robloo thoughts?

I had a thought you might say that. Agreed and done. See PR #4010

@michael-hawker michael-hawker merged commit 2b124ff into CommunityToolkit:master May 3, 2021
@michael-hawker michael-hawker modified the milestones: 7.1, 7.0.2 May 11, 2021
ghost pushed a commit that referenced this pull request Jun 29, 2021
## Fixes #

Fixes some potential crashes with the built-in Windows 10 ColorSpectrum by switching to the WinUI version instead with the latest bug fixes.

 * ColorPicker and ColorSpectrum now derive from the WinUI equivalent controls

<!-- Add a brief overview here of the feature/bug & fix. -->

## PR Type
What kind of change does this PR introduce?
<!-- Please uncomment one or more that apply to this PR. -->

- Bugfix
<!-- - Feature -->
<!-- - Code style update (formatting) -->
- Refactoring (no functional changes, no api changes) 
<!-- - Build or CI related changes -->
<!-- - Documentation content changes -->
<!-- - Sample app changes -->
<!-- - Other... Please describe: -->


## What is the current behavior?
<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->


## What is the new behavior?
<!-- Describe how was this issue resolved or changed? -->


## PR Checklist

Please check if your PR fulfills the following requirements:

- [x] Tested code with current [supported SDKs](../readme.md#supported)
- [ ] ~Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link:~ <!-- docs PR link -->
- [ ] ~Sample in sample app has been added / updated (for bug fixes / features)~
    - [ ] ~Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)~
- [ ] ~New major technical changes in the toolkit have or will be added to the [Wiki](https://github.com/windows-toolkit/WindowsCommunityToolkit/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
     **Anyone customizing the Spectrum shape or components directly in C# will need to switch to Microsoft.UI.Xaml namespace**

<!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. 
     Please note that breaking changes are likely to be rejected within minor release cycles or held until major versions. -->


## Other information

See discussion in #3943 #3943 (comment)
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 helpers ✋ hotfix 🌶 priority 🚩

Projects

None yet

Development

Successfully merging this pull request may close these issues.

possible bug in ColorPicker - CustomPaletteColors property

4 participants