Hi,
I've got an Enum called "DoYouKnow", containing Yes
, No
and Unknown
.
I have a column in a GridView which currently displays "Yes", "No" or "Unknown" in each row, based on a DoYouKnow value I've attached it to using DisplayMemberBinding
.
Instead of displaying I would like to have this column display a tick, a cross or a question mark.
So far the closest I've gotten to getting this working is drawing some pictures and lamenting the fact that if I didn't have to use WPF, I could do this in code without having to bother all you nice people.
Any idea what I should do next?
EDIT: Based on Reed's advice, I have gotten to this stage with my XAML (most of the details have been ripped out, apologies if anything obvious is missing, feel free to ask, for all I know something important IS missing):
<UserControl.Resources>
<l:KnownImageConverter x:Key="imageConverter"/>
</UserControl.Resources>
<Grid>
<ListView>
<ListView.View>
<GridView>
<GridViewColumn Header="Known State" DisplayMemberBinding="{Binding Path=Known, Converter={StaticResource imageConverter}}" />
</GridView>
</ListView.View>
</ListView>
</Grid>
And this is the iValueConverter I've cobbled together:
<ValueConversion(GetType(Known), GetType(Image))>
Public Class KnownImageConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
Select Case CType(value, Known)
Case Known.Yes
Return My.Resources.Yes
Case Known.No
Return My.Resources.No
Case Known.Unknown
Return My.Resources.Unknown
End Select
Return New Image
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
If value Is My.Resources.Yes Then
Return Known.Yes
ElseIf value Is My.Resources.No Then
Return Known.No
ElseIf value Is My.Resources.Unknown Then
Return Known.Unknown
End If
Return Known.Unknown
End Function
End Class
As I said in the comments below, the Images I'm using are all displaying in the ListView as "System.Drawing.Bitmap" instead of my pretty little pictures.