Change ComboBox Popup border colour

BigH61 581 Reputation points
2022-08-02T11:05:13.59+00:00

I would like to be able to change the ComboBox Popup border colour without having to override the whole template is there a simple clean way to achieve this.

Thank you for any assistance.

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,679 questions
0 comments No comments
{count} votes

Accepted answer
  1. Hui Liu-MSFT 40,661 Reputation points Microsoft Vendor
    2022-08-03T02:15:32.68+00:00

    You could refer to the method below to see if it is what you need.
    Xaml:

     <Grid>  
            <ComboBox Name="cb" Loaded="cb_Loaded" Height="50" Width="100" >  
                <ComboBoxItem>Item1</ComboBoxItem>  
                <ComboBoxItem>Item2</ComboBoxItem>  
                <ComboBoxItem>Item3</ComboBoxItem>  
            </ComboBox>  
        </Grid>  
    

    Codebehind:

     private T FindVisualChildByName<T>(DependencyObject parent, string name) where T : DependencyObject  
            {  
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)  
                {  
                    var child = VisualTreeHelper.GetChild(parent, i);  
                    string controlName = child.GetValue(Control.NameProperty) as string;  
                    if (controlName == name)  
                    {  
                        return child as T;  
                    }  
                    else  
                    {  
                        T result = FindVisualChildByName<T>(child, name);  
                        if (result != null)  
                            return result;  
                    }  
                }  
                return null;  
            }  
    
            private void cb_Loaded(object sender, RoutedEventArgs e)  
            {  
    
                Popup popup = FindVisualChildByName<Popup>((sender as DependencyObject), "PART_Popup");  
                Border border = FindVisualChildByName<Border>(popup.Child, "DropDownBorder");  
                border.BorderBrush = Brushes.Red;  
            }  
    

    The result:
    ![227433-image.png


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

    [5]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful