SyntaxEditor in PropertyGrid via attribute-setting

Grids for WPF Forum

Posted 6 years ago by matt2012
Version: 17.2.0662
Avatar

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

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 6 years ago by matt2012
Avatar

Hello,

thank you, I will test this.

Regards

Posted 6 years ago by matt2012
Avatar

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

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

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

Add Comment

Please log in to a validated account to post comments.