Repository navigation
Closed
Labels
difficulty/medium 🤔Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUIkind/bugSomething isn't workingproject/shapes-brushes 🔶Categorizes an issue or PR as relevant to shapes and brushes
Description
Current behavior
Add a <ColorPicker> to any sample project. The following occurs in WASM:
- The color spectrum does not display even though you can click on it.
- The track bar is not visible even though you can interact with it if you know where to click.
- When used in a popup, opening the popup after the first time will not let you interact with the control.
Expected behavior
Should be able to see the color spectrum and track bar. Should be able to interact with it even when shown multiple times in a popup.
How to reproduce it (as minimally and precisely as possible)
Attaching a sample project.
App1.Shared.zip
Workaround
Environment
Nuget Package:
- Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia
- Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia
- Uno.SourceGenerationTasks
- Uno.UI.RemoteControl / Uno.WinUI.RemoteControl
- Other:
Nuget Package Version(s):
Affected platform(s):
- iOS
- Android
- WebAssembly
- WebAssembly renderers for Xamarin.Forms
- macOS
- Skia
- WPF
- GTK (Linux)
- Tizen
- Windows
- Build tasks
- Solution Templates
IDE:
- Visual Studio 2017 (version: )
- Visual Studio 2019 (version: )
- Visual Studio for Mac (version: )
- Rider Windows (version: )
- Rider macOS (version: )
- Visual Studio Code (version: )
Relevant plugins:
- Resharper (version: )
Anything else we need to know?
Metadata
Metadata
Assignees
Labels
difficulty/medium 🤔Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUIkind/bugSomething isn't workingproject/shapes-brushes 🔶Categorizes an issue or PR as relevant to shapes and brushes

Activity
[-]ColorPicker has issues in WASM[/-][+]ColorPicker issues in WASM[/+]francoistanguay commentedon May 12, 2021
@robloo Any of this rings a bell? Should it work? Not yet implemented?
robloo commentedon May 12, 2021
@francoistanguay @jsinsel The ColorPicker was only tested to work with Android and iOS at the time. There is a known issue in Uno where image source invalidation doesn't work (at least this is the best theory). If you set an ImageBrush's ImageSource to a new WritableBitmap and then that WritableBitmap is updated asyncronously later, updates will be ignored and won't ever display. This means the color spectrum is never visible in some cases. For some reason correctly handling this source invalidation was only implemented on a few platforms. ImageBrush/ImageSource likely needs a big refactoring on all platforms as this code is inconsistent and quite messy.
The issue with the slider backgrounds not being visible may be similar. Although, I've seen evidence there has been regressions with controls derived from Slider. No idea what may be going on with Popup. Personally, I've never worked with the WASM head.
Some key pieces of code to look at:
Code where the
WriteableBitmaprepresenting the ColorSpectrum is is created. This is done asynchronously and may occur after theWriteableBitmapwas already added to anImageBrush/ImageSource.uno/src/Uno.UI/Microsoft/UI/Xaml/Controls/ColorPicker/ColorSpectrum.cs
Lines 1158 to 1166 in e1f887c
Code where the
WriteableBitmapis set as theImageSourceof anImageBrushand then theImageBrushis set as the Fill of the spectrumRectangleitself.uno/src/Uno.UI/Microsoft/UI/Xaml/Controls/ColorPicker/ColorSpectrum.cs
Lines 1601 to 1609 in e1f887c
I do not understand fully how changes are propagated by Uno itself. However,
WriteableBitmap,Image,ImageBrushandImageSourceare all involved.Edit: I should add: a new ImageBrush is created and set as Fill each time UpdateBitmapSources() is called so I might be wrong about this being an issue with update propagation as described above. It could also be related to the Shape.Fill property. Anyway, it's been several months since I looked at this and only ported the code to C# so I shouldn't say much about things I don't fully understand. If there are any specific questions related to ColorPicker and debugging this I will be happy to help though.
Xiaoy312 commentedon Aug 11, 2021
fixme:
other issues noticed:
robloo commentedon Aug 11, 2021
@Xiaoy312
I've noticed some regressions in sliders in newer versions of Uno, they don't seem to work at all if you derive from them new controls.
Image invalidation is still an issue and WASM may still not fully support WriteableBitmap. This affects the Spectrum and Sliders both.
On other platforms, such as Android, interaction with the spectrum has also regressed. It is usually not possible to update the color by pressing on the spectrum.
This was a known issue with the string formatting called out in the original PR: feat(ColorPicker): Add ColorPicker, ColorPickerSlider & ColorSpectrum #3955 (Question 1 at the end of the issue description). @MartinZikmund since then found a helper method that seems to automatically do the conversion. I can't find that comment at the moment to know which method he was talking about specifically but it should be a simple code update. We don't want to modify the WinUI strings themselves or its just going to break in the future. Edit: I found the conversation WinUI InfoBar #4427 (comment)
Again, this was called out in the original PR. It is using
ColorHelper.ToDisplayName()which isn't implemented in Uno. The algorithm to implement it is unknown and non-public. There is conditional code built into the upstream WinUI source to disable this. I used this functionality to disable it since Uno does not support it:uno/src/Uno.UI/Microsoft/UI/Xaml/Controls/ColorPicker/ColorSpectrum.cs
Line 173 in a2cfd23
uno/src/Uno.UI/Helpers/WinUI/DownlevelHelper.cs
Line 8 in a2cfd23
I have given up fixing all the related, secondary issues and unsupported features in Uno to get the ColorPicker to work correctly on all platforms. However, I still think the ported code is good and you won't find any issues there (it was well tested on UWP after the C++ -> C# conversion, and then well tested again on Android at the time). If you need help with the ColorPicker code specifically though I will support there. For example, I can take responsibility for number 4 but it will be a while before I get around to it.
Xiaoy312 commentedon Aug 13, 2021
it is working now \o/


edit: the spectrum looks better than that, the gif compression ruined it...
robloo commentedon Aug 14, 2021
@Xiaoy312 Awesome!
Note that there is a bug in the gradient (you might have fixed that already in the PR as you were adjusting code in that area). However, that is the same bug that existed in iOS.
#3955 (comment)
Edit: Added Graphics
Actual

Expected
