-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Is your feature request related to a problem? Please describe.
Currently, customizing the background color of a ComboBox's dropdown popup is very cumbersome. There are two main problems:
- Complexity: There is no simple property to set the dropdown's background color. A developer must resort to creating a completely custom ControlTemplate to change this, which is an extremely verbose and difficult process for what should be a simple customization.
- Transparency Issues: The default ControlTemplate is not designed to handle semi-transparent backgrounds correctly. The ScrollViewer inside PART_Popup has its Background bound to the PART_Popup's Background. When a semi-transparent brush is used, this results in the color being applied twice (color stacking), leading to a final color that is darker and less transparent than intended.
Describe the solution you'd like
I would like to propose adding a new attached property to the ComboBoxAssist helper class:
public static readonly DependencyProperty DropDownBackgroundProperty;
This property, of type Brush, would allow developers to directly and easily set the background of the ComboBox dropdown in XAML.
Describe alternatives you've considered
The only viable alternative currently is to extract and copy the entire default ControlTemplate of the ComboBox from the library's source code and manually modify its internal elements. This approach is not practical for a simple color change as it is very brittle and makes it difficult to receive updates for the control in the future.
Additional context
Through investigation, implementing this feature correctly requires addressing a few key challenges in the existing ControlTemplates:
- Trigger Precedence: The ControlTemplate.Triggers for wpf:ColorZoneAssist.Mode in MaterialDesignFloatingHintComboBoxTemplate will override the popup background. The implementation must integrate the new DropDownBackground property into these triggers, likely using the existing FallbackBrushConverter to give DropDownBackground the highest priority.
- Color Stacking Fix: To solve the transparency issue, the Background property of the ScrollViewer inside PART_Popup should be hardcoded to Transparent.
- Multiple Templates: The Material Design in XAML library uses different ControlTemplates for different ComboBox styles. For this feature to be consistent, the changes must be applied not only to the main MaterialDesignFloatingHintComboBoxTemplate but also to the templates used by MaterialDesignDataGridComboBox.