We use a CellValuePresenter to show an image in the XamDataGrid. Because the images are not in the right format we use a valueconverter. Strangely enough before the value we expect to come into the converter we get a string with the content "Text" first and afterwards another call to the converter with the object we expect. Because our converter expects an Image it throws an exception. We tried to find where the string comes from and it seems to come from inside the XamDataGrid. Why do we get a string "Text" and not a null value?
The Code we use for the XamDataGrid:
Normal 0 21 false false false NL X-NONE X-NONE MicrosoftInternetExplorer4
<i:XamDataGrid DataSource="{Binding CurrentCollection}"
ActiveDataItem="{Binding CurrentObject}"
Name="grdPlanCombinatie"
Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2"
cs:View.UseViewCommandsAsContextMenu="True"
Style="{StaticResource XamDataGrid_TextTrimmingCharacterEllipsis}">
<i:XamDataGrid.FieldLayouts>
<i:FieldLayout Key="parent" IsDefault="False" Settings="{StaticResource ParentFieldLayout}">
<i:FieldLayout.Fields>
<i:UnboundField Label=" "
Name="AfspraakSlot.ImageHeeftEigenLock"
BindingPath="[AfspraakSlot.ImageHeeftEigenLock].Value"
Width="30"
Settings="{StaticResource ImageField}" />
The Code we use for the CellValuePresenter:
<classes:ICSImageToImageSourceConverter x:Key="ICSImageToImageSourceConverter" />
<i:FieldSettings x:Key="ImageField" AllowEdit="False">
<i:FieldSettings.CellValuePresenterStyle>
<Style TargetType="{x:Type i:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type i:CellValuePresenter}">
<Image Stretch="None" Source="{TemplateBinding Value, Converter={StaticResource ICSImageToImageSourceConverter}}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</i:FieldSettings.CellValuePresenterStyle>
</i:FieldSettings>
Hello,
It has been a while since you have made your post, in case you still need support I will be glad to assist you further. I suppose the other community members can benefit from this answer as well. I have been looking through your post and I suggest you use the following code in your Converter’s Converter method in order to check if the value is null or “Text”:
if (value != null) { if (value.ToString() != "Text") { //Add your code } } return Binding.DoNothing;
Feel free to write me if you have further questions.