Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ColorPicker.CustomPalette cannot be styled #379

Open
3 of 24 tasks
hexawyz opened this issue Mar 27, 2024 · 0 comments
Open
3 of 24 tasks

ColorPicker.CustomPalette cannot be styled #379

hexawyz opened this issue Mar 27, 2024 · 0 comments

Comments

@hexawyz
Copy link

hexawyz commented Mar 27, 2024

Describe the bug

Because the CustomPalette property of ColorPicker is explicitly assigned in the code, 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

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:

<local:RgbLightingDefaultPalette x:Key="RgbLightingDefaultPalette" />

<Style x:Key="RgbLightingColorPickerStyle" TargetType="controls:ColorPicker">
    <Setter Property="ColorSpectrumShape" Value="Ring" />
    <Setter Target="CustomPalette" Value="{StaticResource RgbLightingDefaultPalette}" />
</Style>

MainWindow.xaml:

<controls:ColorPicker Style="{StaticResource RgbLightingColorPickerStyle}" />

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
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
  • 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)
  • 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)
  • 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: hexawyz@b7c74e9
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant