C# WPF Enlarge userControl till the ScrollViewer inside won't show its scrollbar
03:39 29 Jun 2026

I have custom RichTextBoxes called MandatRichText, inside a Grid inside a ScrollViewer inside a UserControl. When the user DoubleClicks the UserControl, it needs to grow till the Scrollviewer's scrollbar will disappear.

I tried to use Measure command but it doesn't reach the right size.

This is the Xaml:


    
        
            
                
                
            
            
            
        
    

This is the code. I tried it also with DesiredSize of the Grid or the UserControl, it didn't help:

private void userControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    if (scrollcontainer.ComputedVerticalScrollBarVisibility == Visibility.Visible)
    {
        double widthGap = scrollcontainer.DesiredSize.Width - scrollcontainer.ActualWidth;
        double heightGap = scrollcontainer.DesiredSize.Height - scrollcontainer.ActualHeight;

        this.Width += widthGap;
        this.Height += heightGap;
        Measure(scrollcontainer.DesiredSize);
    }
}
wpf scrollbar scrollviewer