WPF , Getting verticalstretch working as expected!

前端 未结 3 1804
遇见更好的自我
遇见更好的自我 2021-02-15 23:25

I am trying to make the vertical stretch to work as expected i WPF, but for some reason it only takes the space it needs, and not the space available.

First, I am using

3条回答
  •  失恋的感觉
    2021-02-15 23:53

    The default for ItemsControl.ItemsPanelTemplate is StackPanel, which compresses all of its children vertically giving the symptoms you describe.

    The solution code-zoop gave changes this to . This will work well as long as there is can only be one view in the region. But if the region has more than one view they will all be laid on top of each other instead of beside each other.

    If you want a region that can handle multiple views but allow views to stretch to the full size of the region, use a DockPanel instead:

    
      
        
          
        
      
    
    

    This will put the first view in a panel on the left side, the next one beside it, and so on until the last view which will fill all the remaining space.

    If you prefer to have the multiple views stack vertically like they did with StackPanel, you'll have to set that up in ItemContainerStyle:

    
      
        
          
        
      
      
        
      
    
    

提交回复
热议问题