WPF - Very basic ListBox.ItemTemplate Question

前端 未结 3 938
执笔经年
执笔经年 2021-02-05 11:46

Ok, this is an embarassingly simple-looking problem, but is driving me crazy. I\'m learning about DataTemplating and am trying to apply a very VERY simple ItemTemplate to a List

3条回答
  •  醉梦人生
    2021-02-05 12:28

    ItemTemplate wont work when you put ListBoxItem directly as items. General concept is you databind a CRL collection to the ListBox.ItemsSource and then specify the ItemTemplate. Check the below code.

     
            
                
                    
                        
                            
                            
                        
                    
                
                
                    Bob
                    Jim
                    Dave
                    Larry
                    Tom
                
            
        
    

    where sys is xmlns:sys="clr-namespace:System;assembly=mscorlib"

    In this way, there are 5 ListBoxItems getting generated in the background and added to the ListBox.

提交回复
热议问题