Why no horizontal scrollbar in property grid?

Editors for WPF Forum

Posted 2 years ago by Kurt Madland
Version: 22.1.4
Avatar

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 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

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 2 years ago by Kurt Madland
Avatar

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 2 years ago]

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

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.3) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.