microsoft / microsoft/microsoft-ui-xaml
Some controls "disappear" when disabled on a white background - can't change their background disabled color in custom dictionary
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### 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:
### Expected behavior
When disabled, controls background should change to what is configured in custom dictionary instead of disappearing.
### Screenshots
Program start up:

Disabling controls - 2 controls on right disappear:

Re-enabling controls - 2 controls on right reappear:

### 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](https://github.com/user-attachments/files/16937563/Disabled.Controls.zip)
MainWindow.xaml
Click Me
Sample Button
Sample ToggleButton
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;
}
}
}
Contributor guide
Research direction
Reproduce the disabled-control behavior using the attached MainWindow.xaml and MainWindow.xaml.cs sample, including the custom ResourceDictionary entries for the four controls. Then inspect the WinUI control templates and disabled-background resources for AutoSuggestBox, NumberBox, PasswordBox, and TextBox; done means their configured disabled backgrounds remain visible on a white container.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100