Why no horizontal scrollbar in property grid?

Editors for WPF Forum

Posted 1 year ago by Kurt Madland
Version: 22.1.4

When using the sample app, if I reduce the size of the property grid, horizontal scrollbars never appear, and the controls in the editor column become impossible to use. I thought the property grid supported scrolling, why do the scrollbars not appear?

Comments (3)

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA


PropertyGrid does have a ScrollViewer in its template that kicks in for horizontal scrolling when required.  That being said, the default PropertyGrid name/value columns are set up with star-sizing, similar to a Grid panel.  They will shrink as width decreases.  However if you set a MinWidth on them and the columns at MinWidth still don't fit, you will see a horizontal scrollbar.

You can reproduce this in our Columns QuickStart sample if you open its MainControl.InitializeAdditionalColumns method and add these two lines at the end:

propGrid.Columns[0].MinWidth = 180;
propGrid.Columns[2].MinWidth = 180;

Then run the sample and reduce the window to its minimum width to see the horizontal scrollbar appear.

Actipro Software Support

Posted 1 year ago by Kurt Madland

There's no way to set that column width in the xaml; I have to use code behind? I can't have the Column size to fit it's content? 

In my app I cannot hard-code some value for the MinWidth, I am using custom property editors that vary in size depending on the use-case.  So would I then need to somehow programmtically compute which of my property editors is the "widest" at any given time and set the MinWidth to that widest value so the scrollbar appears once the widest editor starts to be cut off?  Do you have any tips on how to do that?  Seems unnecessarily complicated I would expect the scrollbar to appear whenever the content inside is cut off. 

[Modified 1 year ago]

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA

The name and value columns for a PropertyGrid are generated in code, so they cannot be configured in XAML.  They are designed to use star-scaling by default to prevent the need of a horizontal scrollbar.

You can make them auto-fit content if you wish though.  You could put code like below (assuming column 0 is Name and column 1 is Value) either in a PropertyGrid-derived class' constructor, or in a Window that contains the PropertyGrid:

propGrid.Columns[0].MinWidth = 16;
propGrid.Columns[0].MaxWidth = double.NaN;
propGrid.Columns[0].Width = GridLength.Auto;
propGrid.Columns[1].MinWidth = 16;
propGrid.Columns[1].MaxWidth = double.NaN;
propGrid.Columns[1].Width = GridLength.Auto;

That code resets everything so it will fully auto-scale and show the horizontal scrollbar as needed.

Actipro Software Support

The latest build of this product (v24.1.2) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.