[WPF 学习] 8.极简ComboBox的内容模板

一、设置内容模板如下

 
        
            
                
                    
                    
                
                
                    
                        
                        
                            
                                
                                    
                                        
                                    
                                    
                                
                            
                        
                    
                
                
                
            

        

二、前端调用(xaml)

        
            
                aaa
            
            
                bbb
            
        
        

三、代码调用(cs)

            ComboBox cb = new ComboBox() { Background=Brushes.Red,BorderBrush=Brushes.Blue,BorderThickness=new Thickness(2)};
            cb.Items.Add( new TextBox { Text = "aaa" ,Foreground=Brushes.White} );
            cb.Items.Add(new TextBox { Text = "bbb", Foreground = Brushes.Green });
            cb.SelectedIndex = 0;
            cb.Template = Resources["ComboBoxTemplate1"] as ControlTemplate;

四、效果图如下

你可能感兴趣的:([WPF 学习] 8.极简ComboBox的内容模板)