WPF ComboBox Multiple Columns

后端 未结 3 1706
孤街浪徒
孤街浪徒 2020-12-11 06:49

I am just wondering if there is a wpf combobox control that can contain multiple columns?

And if not, what XAML I need to use to achieve this?

I am just loo

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 06:55

    Please Refer these links for Multiple Column Combobox which is implemented by editing combox and comboboxitem Default template/style.

    1)Link1

    2)Link2

    Xaml code : Please take a look at commented Trigger IsHighlighted in ComboboxItem style

     
        
            
                
                    
                
            
            
                
            
        
    
    

    c# code

    public partial class MainWindow : Window
    
    {
    
        private ObservableCollection cities = new ObservableCollection();
    
        public MainWindow()
        {
            InitializeComponent();
            cities.Add(new City() { Name = "Mumbai", State = "Maharashtra", Population = 3000000 });
            cities.Add(new City() { Name = "Pune", State = "Maharashtra", Population = 7000000 });
            cities.Add(new City() { Name = "Nashik", State = "Maharashtra", Population = 65000 });
            cities.Add(new City() { Name = "Aurangabad", State = "Maharashtra", Population = 5000000 });
            DataContext = cities;
        }
    }
    
    class City
    {
        public string State { get; set; }
        public string Name { get; set; }
        public int Population { get; set; }
    }
    

    Output enter image description here

提交回复
热议问题