I am having problems with a listview in WPF C#. I have a class called FaultRecords which contains an integer field, a bitmap image and a string. When I run the code the integer and string appear fine but the image does not. In the column where the image is supposed to be I just get the path to the type instead - "system.windows.media.imaging.bitmapimage". Its driving me crazy.....
Here's my code
public void RecordNewFault()
{
FaultRecords myRecord = new FaultRecords(FaultIndex, PublicVars.SrcBmp, "Hi There!");
lstvFaults.Items.Add(myRecord);
}
public class FaultRecords
{
private int _faultNumber;
public int FaultNumber
{
get { return _faultNumber; }
set { _faultNumber = value; }
}
public BitmapImage _faultImage;
public BitmapImage FaultImage
{
get { return _faultImage; }
set { _faultImage = value; }
}
private string _faultDescription;
public string FaultDescription
{
get { return _faultDescription; }
set { _faultDescription = value; }
}
public FaultRecords(int faultNumber, BitmapImage faultImage, string faultDescription)
{
FaultDescription = faultDescription;
FaultNumber = faultNumber;
FaultImage = faultImage;
}
}
XAML:
<ListView Height="412" HorizontalAlignment="Left" Margin="312,49,0,0" Name="lstvFaults" VerticalAlignment="Top" Width="636" ItemsSource="{Binding}" FontSize="12">
<ListView.View>
<GridView>
<GridViewColumn
DisplayMemberBinding="{Binding Path=FaultNumber}"
Header="Fault No." Width="50"/>
<GridViewColumn
DisplayMemberBinding="{Binding Path=FaultImage}"
Header="Photo" Width="150"/>
<GridViewColumn
DisplayMemberBinding="{Binding Path=FaultDescription}"
Header="Fault Description" Width="300"/>
</GridView>
</ListView.View>
If I just write the Bitmap to the listview on it's own (and remove the XAML bindings) - lstvFaults.Items.Add(PublicVars.SrcBmp);
it works fine.