Disable double click behaviour in property grid

Grids for WPF Forum

Posted 5 months ago by Michael
Version: 20.1.1
Avatar

Some property editors (e.g. ColorBox) change the property to a fixed value when the user double clicks on the property name.

Is it possible to disable this behavour?

I can block all double clicks by overwriting PropertyGrid.PreviewMouseDown. But this also disables double click text selection in text boxes, which I want to retain.

Comments (3)

Posted 5 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michael,

Double-clicking the name cell will call the IPropertyModel.CycleToNextStandardValue method to see if the property model supports cycling values.  If that method returns false, then it will try to move focus into the value cell instead.

It would be up to the IPropertyModel implementation to return false from CycleToNextStandardValue to prevent cycling.  If you did prevent the double-click event itself, then you'd want to only do so if you are over a name cell.

I don't see cycling behavior happening in color editors though, since I don't believe colors define standard values.  It's just focusing the value when I double-click.  Can you tell us how to reproduce that in one of our samples?


Actipro Software Support

The latest build of this product (v21.1.1) was released 3 months ago, which was before the next post in this thread.
Posted 3 months ago by Michael
Avatar

While trying to find a workaround I noticed that I am actually using two different types to store colors, and it seems these two types are treated differently by TypeDescriptorFactory. Here is what I see in the IPropertyModel list returned by GetPropertyModels():

  • System.Windows.Media.Color: HasStandardTypes=False
  • System.Drawing.Color: HasStandardTypes=True

I assume this explains the behaviour. It also explains why the effect does not occur in all of my color properties.

Can you confirm this observation? And, if yes, is there an easy way to override the data model for System.Drawing.Color?

Posted 3 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michael,

Aha, that explains it.  Yes, System.Drawing.ColorConverter does support standard values.

Perhaps you could make a custom class that inherits ColorConverter and overrides GetStandardValuesSupported to return false.  Then you'd have to make a class that inherits PropertyDescriptorPropertyModel and overrides its ConverterCore property to return the custom converter instance.  In addition, you'd have to inherit TypeDescriptorFactory and override its CreatePropertyModel method to return this custom PropertyDescriptorPropertyModel class when the property type is System.Drawing.ColorConverter.

Or you could switch your code to consistently use System.Windows.Media.Color instead of System.Drawing.Color.


Actipro Software Support

Add Comment

Please log in to a validated account to post comments.