How to change default color of WPF Combobox?

JunYoungLee 161 Reputation points
2022-06-06T07:08:57.957+00:00

I want to change the color of Combobox in WPF as below. I tried changing the color with the background property of the Combobox, but the background color of the contents displayed when the combo box is clicked is changed. Is there a way to solve this by changing only my code below without using any additional styles?

<ComboBox x:Name="combo_ftpdia" Width="110" Height="20" Margin="10 5 10 0"  
                          VerticalContentAlignment="Center">  
                      
                    <!--Add Code To Change Color-->  
  
                    <ComboBoxItem Content="C:\"/>  
                    <ComboBoxItem Content="D:\"/>  
                    <ComboBoxItem Content="E:\"/>  
                </ComboBox>  

208654-%E1%84%80%E1%85%B3%E1%84%85%E1%85%B5%E1%86%B72.png

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,671 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,249 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
764 questions
0 comments No comments
{count} votes

Accepted answer
  1. Hui Liu-MSFT 38,251 Reputation points Microsoft Vendor
    2022-06-06T09:43:41.483+00:00

    Get the default style of the Combobox:
    In the Designer -> Right Click the ComboBox -> Edit Template -> Edit a Copy

    It can be changed by modifying the default template:
    208658-combobox-style.txt

    <ComboBox x:Name="combo_ftpdia" Width="110" Height="20" Margin="10 5 10 0" IsEditable="True"  
                      VerticalContentAlignment="Center" Style="{StaticResource ComboBoxStyle1}" >  
                <ComboBoxItem Content="C:\"/>  
                <ComboBoxItem Content="D:\"/>  
                <ComboBoxItem Content="E:\"/>  
            </ComboBox>  
    

    complete code:
    208731-combobox-style.txt
    The result:

    208741-image.png


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful