How to use Custom Color Picker in Actipro PropertyGrid

Grids for WPF Forum

Posted 12 years ago by Charles Onu
Version: 11.2.0553
Avatar

Hi, I am trying out the Actipro Wpf studio.
I am using the propertygrid to dynamically change properties such as fillcolor, border color, thickness etc on a WPF Column chart.

I have a custom color picker control and want to use it  rather than the Actipro BrushPropertyEditor to edit brush properties such as FillColor - this is due to the requirements of my testing.

My thought is that I would have to define the custom color picker control within the propertyGrid's Item Template in the xaml file(rather than have it generated automatically by specifying an EditorAttribute above the property definition).
Can you please show me a sample of how to do this, that is, define the Item Template of the PropertyGrid?

You could also just direct me on how to use the custom color picker with the Actipro PropertyGrid, if you think my suggestion above will not provide the desired
function.

Thanks.

Comments (6)

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

Hi Charles,

If you want your brush editor to be applied to all properties of type Brush, then you would simply define a DataTemplate and associate it like so:

<propgrid:PropertyGrid x:Name="propGrid" SelectedObject="{StaticResource TestObject}">
	<propgrid:PropertyGrid.PropertyEditors>
		<propgrid:PropertyEditor PropertyType="{x:Type Brush}" ValueTemplate="{StaticResource MyBrushTemplate}" />
	</propgrid:PropertyGrid.PropertyEditors>
</propgrid:PropertyGrid>

 In your DataTemplate, you can bind to the associated property value using:

{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type propgrid:IPropertyDataAccessor}}, Mode=TwoWay, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}

 Obviously, the ValidatesOnExceptions, ValidatesOnDataErrors, NotifyOnValidationError, and UpdateSourceTrigger are optional. But those are typically the defaults we used for our BrushEditBox.


Actipro Software Support

Posted 12 years ago by Charles Onu
Avatar

Hi, thanks for your response. My ColorPicker now shows on the Property grid as the Editor for all Brush properties.

However, there another issue presently: when i run the application and click the colorpicker, the pop up for selecting colors comes up but all buttons within, for selection of different colors are totally unresponsive.

My ColorPicker is actually a Custom UserControl (derives from UserControl class). I have tried the control outside a <DataTemplate> tag and the buttons respond correspondingly, so it seems like the <DataTemplate> block over it disables the buttons within the controls in a way. How can I overcome this challenge since the ValueTemplate property only accepts a type of DataTemplate?

Below is the definition of the control withing the DataTemplate:

<DataTemplate x:Key="MyBrushTemplate" DataType="CustomWPFColorPicker:ColorPickerControlView">
          //Custom Color picker control       

          <CustomWPFColorPicker:ColorPickerControlView x:Name="ForeColorPicker" CurrentColor="Red" />
</DataTemplate>

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

Hi Charles,

It would be impossible to say without seeing how the ColorPickerControlView works. If you can please put together a small sample project that reproduces your issue and email it over then we can take a closer look. Be sure to remove any executables or change the extension of the zip file to ensure it gets past our email filters.


Actipro Software Support

Posted 12 years ago by Charles Onu
Avatar

I have done as you requested. Expecting your response soon.

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

Hi Charles,

Thank you for the sample project, but you left out the most important piece of code (which is your ColorPickerControlView). This is the control that appears to not function correctly when used in a DataTemplate. If you can send another project with that control included we can take a look.


Actipro Software Support

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

Hi Charles,

This is a tricky issue and is caused by a MouseLeftButtonDown handler built into the native WPF TreeViewItem element, from which our PropertyGridDataAccessorItem derives. So ultimately the TreeView is stealing the mouse click, when you click inside the Popup. Because of how the TreeView registers the event handler for the MouseDown event, there is no way to work around that code.

This is also only a problem when a UserControl is loaded via Application.LoadComponent (which would always be the case unless the control is defined inline) AND the UserControl.Content property is set (which is the case with your sample). If you define the elements of your UserControl inline with the PropertyGrid, then it works fine.

The easiest way to fix this would be to make your ColorPickerControlView a proper templated Control, instead of a UserControl.


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.