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
465
Converting a boolean column into an image within xamDataGrid
posted

Hello,

I have been trying to solve this simple problem now for a whole day without success and I simply dont see where I do the mistake.  I have already checked the code of the FeatureBrowser and couln't get further.

I use the MVVM pattern and the xamdataGrid is filled through the "Properties" poperty on the MainViewModel:

public BindingList<PropertyRowViewModel> Properties { get; private set ; }

The PropertyRowViewModel is exposing the IsVirtual property.

I can see all the properties as columns populated on the grid without any problem.

I would like to show an image according to whether IsVirtual is set or not and display that picture within the same column.

First I have created a field within the FieldLayouts of teh XamDataGrid:

<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:FieldLayout.Fields>
<igDP:Field Name="IsVirtual" Label="IsVirtual">
<igDP:Field.Settings>
<igDP:FieldSettings CellValuePresenterStyle="{StaticResource iconFieldCell}"/>
</igDP:Field.Settings>
</igDP:Field>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>

Within the Resources I have created the following:

 <Style x:Key="iconFieldCell" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<StackPanel x:Name="stackPanel" Orientation="Horizontal">
<Image Width="50" Source="{Binding Path=IsVirtual, Converter={StaticResource conv}, RelativeSource={RelativeSource Self}}">

And this is my converter:

public class IconConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if((bool)value)
{
return new Uri(@"pack://xx.xx.Servicing.Client;,,/Resources/add2.png");
}
else
{
return new Uri(@"pack://xx.xx.Servicing.Client;,,/Resources/arrow_left_blue.png");
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}

I have set the Build action on both pictures as "Resource".

1) I keep getting the error message on the output window:

System.Windows.Data Error: 39 : BindingExpression path error: 'IsVirtual' property not found on 'object' ''Image' (Name='')'. BindingExpression:Path=IsVirtual; DataItem='Image' (Name=''); target element is 'Image' (Name=''); target property is 'Source' (type 'ImageSource')

 

I also tried using Record.DataItem.IsVirtual instead with the same error message.

Why is it not working? 

2) On another note is it possible within the converter to return the actual image directly from my resx, instead of getting its path to create a Uri? by using this:

return Properties.Resources.arrow_left_blue;

I would really appreciate it, if you would help me on these two questions.
Many Thanks,
Houman