How can I bind a List collection to TabControl headers in WPF?

后端 未结 4 557
说谎
说谎 2020-12-09 09:02

I can get data into my TabControl but the headers have frames around them and I can\'t slick from tab to tab.

What am I doing wrong with the XAML binding syntax on

4条回答
  •  情书的邮戳
    2020-12-09 09:31

    Here ist what I would do

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //create all 
            var customers = new List{
                new Customer {FirstName = "Jim", LastName = "Smith", NumberOfContracts = 23},
                new Customer {FirstName = "Jane", LastName = "Smith", NumberOfContracts = 23},
                new Customer {FirstName = "John", LastName = "Tester", NumberOfContracts = 23}};
    
            //show 
            TheTabControl.ItemsSource = customers;
            TheTabControl.SelectedIndex = 0;
        }
    
    
    public class Customer
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public int NumberOfContracts { get; set; }
    }
    

    And on the XAML side

                
        
                                
                                            
                     
                                        
            
        
        
            
                                            
                    This is  
                
            
        
    
    

提交回复
热议问题