WPF clipping even when no clipping is desired - how to turn it off?

后端 未结 2 1385
南方客
南方客 2021-01-11 10:17

I need to float out some content out of the ListBox as specified in a DataTemplate for an ListBox.ItemTemplate. I am using Rende

2条回答
  •  [愿得一人]
    2021-01-11 10:43

    The ListBoxItem's are getting clipped by the ScrollViewer in the ListBox Template. To work around this I think you'll need to remove the ScrollViewer from the Template and if you need scrolling you can wrap the ListBox in a ScrollViewer

    
        
            
                
                    
                        
                    
                    
                        
                            
                        
                    
                
            
            
                
                    
                        
                            
                        
                    
                
             42
        
    
    

    Update

    The ScrollViewer in the Template will generate a ScrollContentPresenter which in turn has the following GetLayoutClip

    protected override Geometry GetLayoutClip(Size layoutSlotSize)
    {
        return new RectangleGeometry(new Rect(base.RenderSize));
    }
    

    This class is Sealed so you can't derive from it to override this method. You would have to implement your own ScrollContentPresenter (e.g MyScrollContentPresenter) and probably your own ScrollViewer that uses MyScrollContentPresenter as well to make this work (and if you return null in this method I think that some items below the bounds of the ListBox could become visible as well)

提交回复
热议问题