WPF - Very basic ListBox.ItemTemplate Question

前端 未结 3 940
执笔经年
执笔经年 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:16

    You can use ItemContainerStyle instead of ItemTemplate if you want to add ListBoxItems directly to the ListBox.

    Doing so, however, is only recommended when you need unique characteristics on a per item level.

    If you are planning on all the items looking the same or making a dynamic list using ItemsSource, I would recommend you add strings (or another custom object) to your list and use ItemTemplate to display your items. (see Jobi Joy's answer)

    Here's an example using ItemContainerStyle:

        
    
            
                
            
    
            
                Bob
                Jim
                Dave
                Larry
                Tom
            
        
    

提交回复
热议问题