Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2030
XamColorPicker inside XamDataGrid and null values
posted

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 { getset; }
public byte? Green { getset;}
public byte? Blue { getset; }

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