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

Some controls "disappear" when disabled on a white background - can't change their background disabled color in custom dictionary #9989

Open
johnt-star opened this issue Sep 9, 2024 · 0 comments
Labels
area-Styling team-Controls Issue for the Controls team

Comments

@johnt-star
Copy link

Describe the bug

Controls are not visible when disabled, when the are placed on a container with a white background.

For most controls, this can be fixed by setting the control's BackgroundDisabled color in a custom dictionary.

However, this fix does not work for the TextBox type controls, specifically AutoSuggestBox, NumberBox, PasswordBox and TextBox.

Steps to reproduce the bug

I am including an app that demonstrates the issue - see screenshots.

The app shows 5 controls with the left most button disabling/enabling the other 4 controls.

Clicking the "Click Me" button disables the other 4 controls, and the 2 controls on the right disappear.

Clicking the same button enables the other 4 controls and the 2 controls on the right.

Note that these are the custom dictionary entries for the 4 controls to set their Disabled Background Colors:

<!-- Button Customizations -->
<SolidColorBrush x:Key="ButtonBackgroundDisabled" Color="LightBlue" />

<!-- ToggleButton Customizations -->
<SolidColorBrush x:Key="ToggleButtonBackgroundDisabled" Color="LightGreen" />

<!-- NumberBox Customizations -->
<SolidColorBrush x:Key="NumberBoxBackgroundDisabled" Color="LightBlue" />

<!-- TextBox Customizations -->
<SolidColorBrush x:Key="TextBoxBackgroundDisabled" Color="LightGreen" />

Expected behavior

When disabled, controls background should change to what is configured in custom dictionary instead of disappearing.

Screenshots

Program start up:
image

Disabling controls - 2 controls on right disappear:
image

Re-enabling controls - 2 controls on right reappear:
image

NuGet package version

Windows App SDK 1.6.0: 1.6.240829007

Packaging type

Unpackaged

Windows version

Windows 10 version 22H2 (19045, 2022 Update)

IDE

Visual Studio 2022

Additional context

Below are the main xaml and cs files.

Attaching entire project in zip file
Disabled Controls.zip

MainWindow.xaml

<StackPanel Width="800" Height="200" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Background="White">
    <Button x:Name="myButton" Click="myButton_Click" Foreground="Black" Background="Gray">Click Me</Button>
    <Button x:Name="ButtonSample" Foreground="Black" Background="Gray">Sample Button</Button>
    <ToggleButton x:Name="ToggleButtonSample" Foreground="Black" Background="Gray">Sample ToggleButton</ToggleButton>
    <NumberBox Width="100" Height="30" x:Name="NumberBoxSample" PlaceholderText="Number Box" Foreground="Black" Background="Gray"></NumberBox>
    <TextBox Width="100" Height="30"  x:Name="TextBoxSample" PlaceholderText="Text Box" Foreground="Black" Background="Gray"></TextBox>
</StackPanel>

MainWindow.xaml.cs:
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace Disabled_Controls
{
///


/// An empty window that can be used on its own or navigated to within a Frame.
///

public sealed partial class MainWindow : Window
{
private bool BoolEnabledState;

    public MainWindow()
    {
        this.InitializeComponent();

        BoolEnabledState = true;
    }

    private void myButton_Click(object sender, RoutedEventArgs e)
    {
        SetControlEnabledState();
    }

    private void SetControlEnabledState()
    {
        BoolEnabledState = !BoolEnabledState;

        if (BoolEnabledState)
        {
            myButton.Content = "Disable Controls";
        }

        else
        {
            myButton.Content = "Enable Controls";
        }

        ButtonSample.IsEnabled = BoolEnabledState;
        ToggleButtonSample.IsEnabled = BoolEnabledState;

        NumberBoxSample.IsEnabled = BoolEnabledState;
        TextBoxSample.IsEnabled = BoolEnabledState;
    }
}

}

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

No branches or pull requests

2 participants