Reputation: 93
I'm working with a XamGrid from Infragistics and I have followed the example from the following page to create a custom column class of buttons:
My goal is to create a custom column class of images that can be filtered.
I have my XAML tag defined as:
<util:FilterableImageColumn
Key="Severity"
ValueConverter="{StaticResource EventSeverityToImageConverter}"
...>
Meaning that I have created a custom Column called FilterableImageColumn. I.E.
public class FilterableImageColumn : Column
This tag also has a ValueConverter called EventSeverityToImageConverter associated with it:
ValueConverter="{StaticResource EventSeverityToImageConverter}"
What this does is create a specific image based on the value received. It is defined like:
public class EventSeverityToImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
BitmapImage severityIcon = null;
try
{
if (value != null)
{
Uri uri = null;
Severities source = (Severities)value;
switch (source)
{
case Severities.Informational:
uri = new Uri("image1");
break;
case Severities.Warning:
uri = new Uri("image2");
break;
case Severities.Critical:
default:
uri = new Uri("image3");
break;
}
if (uri != null)
{
severityIcon = new BitmapImage();
severityIcon.BeginInit();
severityIcon.UriSource = uri;
severityIcon.EndInit();
}
}
}
catch (Exception ex)
{
LoggingProvider.WriteExceptionLogEntry(ex);
}
return severityIcon;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
Now, following the instructions in the link given we create a FilterableImageColumnContentProvider instead of a ButtonColumnContentProvider. (I have also taken the default code given in the linked example for the related ContentBinding properties from the ButtonColumn class and moved it to my FilterableImageColumn class)
FilterableImageColumnContentProvider : ColumnContentProviderBase
Of which I have managed to change ResolveDisplayElement to show an image instead of the button by doing the following:
public override FrameworkElement ResolveDisplayElement(Cell cell, Binding cellBinding)
{
_column = (FilterableImageColumn)cell.Column;
Binding binding = new Binding{ Source = _image.Source};
if (_column.Content == null)
{
binding.Mode = BindingMode.OneWay;
if (_column.ContentBinding != null)
{ this._image.SetBinding(Image.SourceProperty,_column.ContentBinding);
}
else
{
this._image.SetBinding(Image.SourceProperty, binding);
}
}
else
{
binding = new Binding("Content");
binding.Source = _column;
this._image.SetBinding(Button.ContentProperty, binding);
}
return _image;
}
I have hard coded the _image temporarily to see if it will appear using the above, and it does. I've hard coded it as follows:
Image _image;
public FilterableImageColumnContentProvider()
{
Uri uri = new Uri("myImg");
_image = new Image();
_image.BeginInit();
_image.Source = new BitmapImage(uri);
_image.EndInit();
}
My question is, how can I gain access to what my ValueConverter (EventSeverityToImageConverter) has created from within my custom FilterableImageColumn or FilterableImageColumnContentProvider class?
I essentially want to be doing what happens in the EventSeverityToImageConverter from within my FilterableImageColumn or FilterableImageColumnContentProvider. As in, I want to switch between images depending on what I've received.
Currently with the example code I've provided, the column is displayed with only the image I've hard coded (which makes sense) though it does have knowledge of the underlying Severity I have received as made evident in the Filter.
As you can see, the underlying definition of this image is Critical
Where as this one has the underlying definition of the image being Informational
Clearly the information is there somewhere, but I don't know how to access it from within my FilterableImageColumn/FilterableImageColumnContentProvider in order to switch the image on that Severity type (the Critical or Informational string that we see).
Any suggestions would be appreciated.
Basically if I can change
Binding binding = new Binding{ Source = _image.Source};
to the severityIcon I create in the EventSeverityImageConverter.
Binding binding = new Binding{ Source = _severityIcon};
I'd have my solution.
Upvotes: 0
Views: 206