WPF ComboBox Multiple Columns

后端 未结 3 1708
孤街浪徒
孤街浪徒 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 07:19

    Because I found, Heena, that your Xaml does not provide selected dropped down items to be highlighted I modified your code as follows:

    Xaml

    
        
            
                
                    
                    
                
            
        
        
            
        
      
    

    C#

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        cities.Add(new City() { Name = "Boston", State = "MA", Population = 3000000 });
        cities.Add(new City() { Name = "Los Angeles", State = "CA", Population = 7000000 });
        cities.Add(new City() { Name = "Frederick", State = "MD", Population = 65000 });
        cities.Add(new City() { Name = "Houston", State = "TX", Population = 5000000 });
        cbCities.DataContext = cities;
    }
    
    class City
    {
        public string State { get; set; }
        public string Name { get; set; }
        public int Population { get; set; }
    }  
    

    Output

    enter image description here

提交回复
热议问题