Specify the max number of columns for a WrapPanel in WPF

前端 未结 4 507
广开言路
广开言路 2021-02-07 03:13

I have a WrapPanel, And I want to specify the Max number of its columns. So, for example, when my Collection \"ObjectCollection\" (binded to this WrapPanel) contains only 4 elem

4条回答
  •  一向
    一向 (楼主)
    2021-02-07 03:54

    You can control the number of columns by setting the width of the wrap panel. I bind the width of the wrap panel to the ActualWidth of a container like Border. That way, the number of columns is dynamic and is based on the width of the window.

    
            
                 
                      
                      
                  
    
                  
                      
                  
    
                  
                      
                          
                              
                          
                      
                            
                                
                                    
                                        
                                            
                                            
                                        
    
                                        
    
                                        
                                            
                                            
                                            
                                            
                                        
    
                                    
                                
                            
                        
    

提交回复
热议问题