CommunityToolkit / CommunityToolkit/Windows

ColorPicker.CustomPalette cannot be styled

Aperta
#379 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
components::controls::colorpicker feature request :mailbox_with_mail: ux 🖌️
Lingua principale
C#
Stelle
1.1k
Fork
166
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### Describe the bug

Because the `CustomPalette` property of `ColorPicker` is [explicitly assigned in the code](https://github.com/CommunityToolkit/Windows/blob/main/components/ColorPicker/src/ColorPicker.cs#L968), it prevents the property to be styled.
Style setters will always have les priority than directly assigned values, with the assumption that those values come from the final user. In this case, the FluentPalette assigned would override any style defined, as it is assigned in the same way user code would do.

This issue can be worked around by listening for the `Loaded` event and manually overriding the property there, however, in addidition to defeating the purpose of dependency properties, it is not convenient, and can lead to issues. (e.g. in the case of a ColorPickerButton, the ColorPicker can sometimes be null when the event handler is called. From what I understand this would occur if the component is initally `Visibility.Collapsed`)

### Steps to reproduce

```text
In an empty project:
1. Create an implementation of IColorPalette (For example: https://github.com/hexawyz/Exo/blob/master/Exo.Settings.Ui/RgbLightingDefaultPalette.cs)
2. Add a new `ColorPickerStyle` in `App.xaml`
3. Add a ColorPicker in your main page, using the style defined in your app.xaml
4. Run the application, and observe the custom palette displayed by `ColorPicker`
```

With the color palette example linked above:

App.xaml:
````xaml

<Setter Property="ColorSpectrumShape" Value="Ring" />
<Setter Target="CustomPalette" Value="{StaticResource RgbLightingDefaultPalette}" />

````

MainWindow.xaml:
````xaml

````

### Expected behavior

The custom color palette should be used in the `ColorPicker` on which the custom style has been applied, instead of the `FluentColorPalette`.

### Screenshots

![image](https://github.com/CommunityToolkit/Windows/assets/8518235/c1794825-e895-41f6-b214-4f1175a849f4)
The `ColorPicker` in the background has the custom style applied and does not display the custom palette.
The `ColorPicker` in front has the `CustomPalette` property manually assigned and correctly displays the custom palette.

### Code Platform

- [ ] UWP
- [X] WinAppSDK / WinUI 3
- [ ] Web Assembly (WASM)
- [ ] Android
- [ ] iOS
- [ ] MacOS
- [ ] Linux / GTK

### Windows Build Number

- [ ] Windows 10 1809 (Build 17763)
- [ ] Windows 10 1903 (Build 18362)
- [ ] Windows 10 1909 (Build 18363)
- [ ] Windows 10 2004 (Build 19041)
- [ ] Windows 10 20H2 (Build 19042)
- [ ] Windows 10 21H1 (Build 19043)
- [ ] Windows 10 21H2 (Build 19044)
- [ ] Windows 10 22H2 (Build 19045)
- [X] Windows 11 21H2 (Build 22000)
- [ ] Other (specify)

### Other Windows Build number

_No response_

### App minimum and target SDK version

- [ ] Windows 10, version 1809 (Build 17763)
- [ ] Windows 10, version 1903 (Build 18362)
- [ ] Windows 10, version 1909 (Build 18363)
- [ ] Windows 10, version 2004 (Build 19041)
- [ ] Windows 10, version 2104 (Build 20348)
- [X] Windows 11, version 22H2 (Build 22000)
- [ ] Other (specify)

### Other SDK version

_No response_

### Visual Studio Version

2022, Preview

### Visual Studio Build Number

_No response_

### Device form factor

Desktop

### Additional context

I've hastily put up an example of how this could be fixed here: https://github.com/hexawyz/CommunityToolkit-Windows/commit/b7c74e906356a66627518a2bcbfad241540c583c
I assume this is enough, but a better fix would likely be to assign the `CustomPalette` within the `DefaultColorPickerStyle` only.

NB: This problem has been present for a long time and was already existing in the original repo: https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/main/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPicker.cs#L1062
AFAIK, it is not dependent on the version of Windows or of the SDK, so you should ingore those informations.

### Help us help you

Yes, I'd like to be assigned to work on this item.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia in ColorPicker.cs, in corrispondenza della proprietà CustomPalette assegnata esplicitamente, e confrontala con il commit di correzione proposto collegato nell'issue. Verifica come DefaultColorPickerStyle dovrebbe fornire la FluentColorPalette, quindi verifica che una CustomPalette a livello di stile venga mantenuta e utilizzata da ColorPicker.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
desktop, frontend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.