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

Can't set Foreground and Background colours for Checkbox #9236

Open
johnt-star opened this issue Nov 19, 2023 · 4 comments
Open

Can't set Foreground and Background colours for Checkbox #9236

johnt-star opened this issue Nov 19, 2023 · 4 comments
Labels
team-Controls Issue for the Controls team

Comments

@johnt-star
Copy link

Describe the bug

Setting Foreground and Background properties have no effect on Checkbox.

Checkbox text colour remains white

This means checkboxes can;t be used on containers with white backgrounds.

Steps to reproduce the bug

  1. Create a new project in VS using the Blank App (WinUI 3 in Desktop) template.
  2. In MainWindow.xaml, replace the contents of StackPanel with the contents shown in screen grab below

image

Expected behavior

Foreground and Background properties should be customizable

Screenshots

Text remains white instead of black text on aliceblue background.

image

If container background is white then text is lost

image

NuGet package version

Windows App SDK 1.4.3: 1.4.231115000

Packaging type

No response

Windows version

Windows 10 version 22H2 (19045, 2022 Update)

IDE

Visual Studio 2022

Additional context

Project files:
CheckBoxSample.zip

@castorix
Copy link

You can change the resources : CheckBoxForegroundChecked, CheckBoxForegroundUnchecked, CheckBoxForegroundCheckedPointerOver, etc...
Test in Red :
CheckBox

@johnt-star
Copy link
Author

Thank you for your reply!

In my app, I am already statically setting the resources for the checkbox in a xaml file.

However, what I need is the ability to set Foreground and Background colours dynamically, from C#, based on user input.

Is there a way to do this, since the above CheckBox* properties used in the resource file are not exposed, or do I need to do some trickery in order to gain access to them?

Thanks in advance!

@castorix
Copy link

By code, a way can be by changing colors of elements in the Visual Tree
For example, for the Foreground, you can change the Foreground of the TextBlock (cb1 is the name of CheckBox) :

var tb = FindChildElement<TextBlock>(cb1);
tb.Foreground = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 0, 0, 255));

FindChildElement can be found in MainWindow.xaml.cs (I had copied/translated it from MS samples)

@johnt-star
Copy link
Author

Thanks again for your response.

I will look at your suggestion.

It would be nice if Microsoft provided consistent access to all the properties.

I don't think it is reasonable to think that some properties should be static and not accessible from code.

Hopefully, moving forward, the properties that can only be accessed in resource files are also accessible from C# code.

@bpulliam bpulliam transferred this issue from microsoft/WindowsAppSDK Jan 11, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Jan 11, 2024
@bpulliam bpulliam added team-Controls Issue for the Controls team and removed needs-triage Issue needs to be triaged by the area owners labels Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Controls Issue for the Controls team
Projects
None yet
Development

No branches or pull requests

3 participants