WPF repeating elements

后端 未结 3 666
执念已碎
执念已碎 2021-02-09 21:56

I have a UserControl that is a button, with certain characteristics, and I have a window that has several of these buttons in their \"normal\" style. On this same window, I hav

3条回答
  •  梦毁少年i
    2021-02-09 22:39

    A better way would be to create a data-object in code that represents the 30 items that you want in your UI, for example:

    class DataObject
    {
      string Tag {get;set;}
      string Content {get;set;}
    }
    

    (I am sure you can come up with a better name than that!). Then create your 30 items and set them as the ItemsSource of an ItemsControl:

    List myObjects = new List();
    // populate here
    itemsControl.ItemsSource = myObjects
    

    Your ItemsControl has a DataTemplate that is used to render each item:

    
      
      
        
          
        
      
      
      
        
           
        
      
    
    

提交回复
热议问题