Hello,
the XamColorPicker sits inside a XamDataGrid and works very fine - unless the underlying value of the color is null. In this case I receive a number of binding errors.
System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='<null>' BindingExpression:Path=ColorPicker.SelectedColorPreview; DataItem='ColorPickerDialog' (Name='ColorPickerDialog'); target element is 'AdvancedColorShadePicker' (Name=''); target property is 'CurrentColor' (type 'Color')
The XAML for the template looks like this:
<igDP:XamDataGrid.Resources> <Style TargetType="igDP:CellValuePresenter" x:Key="ColorPicker"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <ig:XamColorPicker SelectedColor="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:CellValuePresenter}},Path=Record.DataItem.Farbe,Mode=TwoWay}" /> </DataTemplate> </Setter.Value> </Setter> </Style> </igDP:XamDataGrid.Resources>
The field itself:
<igDP:Field Label="Farbe" Name="Farbe" IsReadOnly="False" AllowEdit="True" DisallowModificationViaClipboard="True"> <igDP:Field.Settings> <igDP:FieldSettings CellValuePresenterStyle="{StaticResource ColorPicker}" /> </igDP:Field.Settings> </igDP:Field>
The underlying object looks like this: It has seperate RGB properties that are matched together. In the case of empty RGB I return null.
public byte? Red { get; set; } public byte? Green { get; set;} public byte? Blue { get; set; }public Color? Farbe { get { if (this.Red.HasValue && this.Green.HasValue && this.Blue.HasValue) { return Color.FromRgb(this.Red.Value, this.Green.Value, this.Blue.Value); } else { return null; } } set { this.Red = value.Value.R; this.Green = value.Value.G; this.Blue = value.Value.B; this.OnPropertyChanged(); } }
It seems that this is releated to the derived palettes: Every time I move the mouse of one of these derived palettes a new binding error is created.
The example on https://www.infragistics.com/community/forums/t/63261.aspx shows the same problem.
Please advice how null values should be handled with a XamColorPicker in a XamDataGrid.
Thanks
Niko
Hello Niko,
It appears that this binding error that you are seeing is coming from the fact that the AdvancedColorShadePicker.CurrentColor property currently accepts a non-nullable Color type. This property is tied to the SelectedColorPreview property which is tied to the SelectedColor property of the XamColorPicker, which both accept nullable Color types. This was likely an oversight on our end, and should be changed to Color? for the AdvancedColorShadePicker.CurrentColor property.
In order to work around these binding errors, I have a couple of recommendations. The simplest recommendation in this case is to return Colors.Transparent instead of null for your "Farbe" property. I realize this may not be possible on your end, though, and so I have found an alternate route as well.
The binding issue in this case is coming from the default style for ColorPickerDialog, which the above mentioned AdvancedColorShadePicker is used in. This default style exists in the generic.xaml file commonly found at the following directory:
C:\Program Files (x86)\Infragistics\<your version here>\WPF\DefaultStyles\ColorPicker
I would recommend locating it, and including it as a resource in your project. In doing so, I would recommend you create a converter that converts null to Colors.Transparent for the CurrentColor binding on the AdvancedColorShadePicker, and apply this converter to that binding for use with the color picker controls in your application. This will avoid the error you are seeing, and I am attaching a sample project to demonstrate.
I am also creating a private support case for you so that you can track the status of the issue I will be logging in order to have this Color property changed to a Color? property. This support case has an ID of CAS-187292-T5Z9P3 and you can access it here: https://www.infragistics.com/my-account/support-activity.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Hello Andrew,
a follow up question: The XamColorpicker has the possibility to show advanced editor. When I use XamColorpicker as standallone control it works fine: I select a color inside the color area press the button OK and I am done. When the colorpicker sits inside a XamDataGrid it needs a mousedoubleclick inside the color area to accept the selection. If I click only once and move the mouse, the small circle inside the color area follows my move.
It's not a big thing, but maybe there is a simple solution to stop that behavior.