Custon Editors

Grids for WPF Forum

Posted 6 years ago by Caer_dalben
Version: 12.2.0570
Avatar

I am currently evaluation your PropertyGrid.

One thing that is not described satisfactory in your sample-application is how selfwritten Custom Editors can be integrated.

The only example I could find is the "Property Editors Quick Start" example.

It is not targeting, that you define all the properties you want to display statically in XAML, and define one editor for each of those properties right where those properties are defined themselfs. (Who will ever use a propertyGrid in such a way?)

 

I have several properties that have classes as parameters. ( public MyClass MyProperty { get; set; } )

What I need is an editor that is described in XAML in form of a Datatemplate, and that is used whenever a property of a certain type (MyClass) is displayed in the grid. (Maybe together with a hint in form of some EditorAttribute on top of the property)

What I need in addition is information on how to bind the Datatemplate-Editor to properties of MyClass and how to bring up a dialog for advanced editing of MyClass.

Is there any sample that shows things like that? Is there any sample that shows how selfwritten custom editors are linked to properties dynamically?

Every hint on that issue is appreciated!

Greetings,

Comments (1)

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

Hi, thanks for evaluating our product.  It doesn't look like we currently have a sample that shows your exact scenario.

But the "Property Editors" topic in the documentation file will be very helpful since it gives information related to these sorts of things that you need.  The easiest way to do it is probably to look at the "Modifying Global Definitions using XAML" section in there.  That shows how you can add hooks for certain property types (like MyClass) to use a certain property editor.

The property editor used can be any of the built-in ones (also described in that topic) or can be a custom one where you give a custom data template.  As an example, here's the source for our built-in one that is used to show a dialog opening button:

<DataTemplate x:Key="{x:Static propgridEditors:BuiltinEditors.DialogTextBoxValueTemplateKey}">
	<Grid>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="*" />
			<ColumnDefinition Width="Auto" />
		</Grid.ColumnDefinitions>
		<TextBox x:Name="textBox" Margin="0" Padding="0" 
				BorderThickness="0" Background="Transparent" MaxLines="1"
				Text="{Binding ValueAsString, RelativeSource={RelativeSource AncestorType={x:Type propgridPrimitives:IPropertyDataAccessor}}, Mode=TwoWay, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, NotifyOnValidationError=True, Converter={StaticResource NoOpConverter}}" />
		<shared:PopupButton Grid.Column="1" Content="..." DisplayMode="ButtonOnly" IsTransparencyModeEnabled="True"
				Command="{x:Static propgrid:PropertyGrid.ShowPropertyDialogCommand}"
				CommandParameter="{Binding RelativeSource={RelativeSource AncestorType={x:Type propgridPrimitives:IPropertyDataAccessor}}}" />
	</Grid>

	<DataTemplate.Triggers>
		<DataTrigger
				Binding="{Binding IsReadOnly, RelativeSource={RelativeSource AncestorType={x:Type propgridPrimitives:IPropertyDataAccessor}}}"
				Value="true">
			<Setter TargetName="textBox" Property="IsReadOnly" Value="true" />
			<Setter TargetName="textBox" Property="Foreground" Value="{DynamicResource {x:Static themes:AssetResourceKeys.ControlForegroundDisabledBrushKey}}" />
		</DataTrigger>
		<DataTrigger Binding="{Binding Path=(propgrid:PropertyGrid.IsReadOnly), RelativeSource={RelativeSource Self}}"
				Value="true">
			<Setter TargetName="textBox" Property="IsReadOnly" Value="true" />
			<Setter TargetName="textBox" Property="Foreground" Value="{DynamicResource {x:Static themes:AssetResourceKeys.ControlForegroundDisabledBrushKey}}" />
		</DataTrigger>
	</DataTemplate.Triggers>
</DataTemplate>


Actipro Software Support

The latest build of this product (v2018.1 build 0675) was released 12 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.