Horizontal scroll for stackpanel doesn't work

后端 未结 2 731
一整个雨季
一整个雨季 2020-11-27 23:02

I try to create a scrollable horizontal StackPanel but I do not succeed very well...

Currently I have my StackPanel with an auto width (and the problem

2条回答
  •  执笔经年
    2020-11-27 23:56

    Currently I have my stackpanel with an auto width (and the problem is maybe here) that contains some items like grids.

    This is your problem. A StackPanel measures its children with infinite horizontal space if its Orientation property is set to Horizontal and infinite vertical space if it is set to Vertical. So you will have to specify an explicit width for the StackPanel itself or the ScrollViewer for this to work.

    Alternatively you could put the ScrollViewer in a Panel that measures its children, like for example a Grid (but not a StackPanel). This works for example:

    
    
        
            
                
                    
                
                
                
                
                
                
                
                
            
        
    
    
    

    But this doesn't because the StackPanel is considered to have an infinite width:

    
        
            
                
                    
                
                
                
                
                
                
                
                
            
        
    
    

    Putting ScrollViewers inside StackPanels is a bad idea.

提交回复
热议问题