Question

SyntaxEditor in PropertyGrid via attribute-setting

Posted 8 months ago by Avatar matt2012

Hello,

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 8 months ago by Actipro Software Support - Cleveland, OH, USA

Hello,

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:PropertyGrid.PropertyEditors>
		<grids:PropertyEditor PropertyName="Title">
			<grids:PropertyEditor.ValueTemplate>
				<DataTemplate>
					<editor:SyntaxEditor IsMultiLine="False"
					    IsTextDataBindingEnabled="True" Text="{Binding Path=Value, Mode=TwoWay}" />
				</DataTemplate>
			</grids:PropertyEditor.ValueTemplate>
		</grids:PropertyEditor>
	</grids:PropertyGrid.PropertyEditors>
</grids:PropertyGrid>

Actipro Software Support
Posted 8 months ago by matt2012

Hello,

thank you, I will test this.

Regards

Posted 3 months ago by matt2012

Hello,

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 3 months ago by Actipro Software Support - Cleveland, OH, USA

Hello,

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

Add a Comment

Please log in to a validated account to post comments.