SyntaxEditor in PropertyGrid via attribute-setting

Posted 6 months ago by Avatar matt2012


I use the propertygrid in MVVM environment.
The settings of the properties are done with attributes e.g. the sort order, localizations and the used editors.
Now I want to use the syntaxeditor for some properties.
Is it possible to do that with the syntaxeditor in single-line-mode?
Is there an example? I didn't find a example using the syntaxeditor in the propertygrid.

Thanks for the answers.

Comments (4)

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


Yes, you can combine the SyntaxEditor concepts of single-line mode and data binding, and use a PropertyGrid property editor.  For instance, this test makes SyntaxEditor edit a Window.Title:

<grids:PropertyGrid DataObject="{Binding ElementName=window}">
		<grids:PropertyEditor PropertyName="Title">
					<editor:SyntaxEditor IsMultiLine="False"
					    IsTextDataBindingEnabled="True" Text="{Binding Path=Value, Mode=TwoWay}" />

Actipro Software Support
Posted 6 months ago by matt2012


thank you, I will test this.


Posted 1 month ago by matt2012


I have done this with the following binding:
Text="{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type propgrid:IPropertyDataAccessor}}, Mode=TwoWay}"
and it works fine.

Now I have another question.
Currently I select the properties via the property name.
Now I have the problem that there are more than one properties have to use the syntax editor.
All the properties have the same suffix.
Is there a way I can write my own logic to select if the property have to use the syntax editor.
Using the PropertyType is not the solution because there are other properties with the same type.

Thank you for the answers.

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


Based on what you describe above, it sounds like you are using the older PropertyGrid version.  You could use EditorAttribute on each property that should get this property editor.  Note that you have to specify it like this:

[Editor(typeof(SyntaxEditorPropertyEditor), typeof(PropertyEditor))]

Where SyntaxEditorPropertyEditor is a PropertyEditor-derived class that would indicate the value template to use.  

In the newer PropertyGrid control that is in our v2017.2 Grids assembly, EditorAttribute still works, but you also can make a class that inherits PropertyGridValueTemplateSelector and set that to the PropertyGrid.ValueTemplateSelector property.  The PropertyGridValueTemplateSelector.SelectTemplate method is called any time PropertyGrid is used to pick a DataTemplate to use for editing a value.  It runs through the logic of looking for things like EditorAttribute.  Thus by overriding the SelectTemplate method, you could change its behavior in one central spot without using the PropertyEditors collection or EditorAttribute.

Actipro Software Support
Information The latest build of this product (2018.1 build 0670) was released 4 days ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.