WPF repeating elements

后端 未结 3 670
执念已碎
执念已碎 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条回答
  •  北荒
    北荒 (楼主)
    2021-02-09 22:36

    I guessed that ColinE's response was off the top of his head, and I gave him a +1 for pointing me in the right direction [THANKS], although it didn't exactly work. What I ended up with was close:

    In the constructor for the window, to set up the 30 almost-identical lines:

    var numberButtons = Enumerable.Range( 1, 30 )
        .Select( r => new KeyValuePair( r.ToString( ), r.ToString( ) ) )
        .ToList( );
    numberButtonItems.ItemsSource = numberButtons;
    

    Then, this xaml (note that "Caption" is a property of our user control, so it won't work for you):

    
        
        
            
                 
            
       
       
       
            
                 
            
       
     
    

提交回复
热议问题