Hi,
I have a XamDataGrid with some fields where I display a status as a BitmapSource via an IValueConverter.
On screen this works well. But when i print my grid all fields show the same image although my converter is called with the right value for each field.
This is my converter:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { try { DB.WFAG.StatusFarben status = (DB.WFAG.StatusFarben)System.Convert.ToInt16(value); switch (status) { case WFCS.Infrastruktur.DB.WFAG.StatusFarben.Lila: return BitmapSourceFromImage(Properties.Resources.uv_on_16); break; case WFCS.Infrastruktur.DB.WFAG.StatusFarben.Blau: return BitmapSourceFromImage(Properties.Resources.blue_on_16); break; case WFCS.Infrastruktur.DB.WFAG.StatusFarben.Gelb: return BitmapSourceFromImage(Properties.Resources.yellow_on_16); break; case WFCS.Infrastruktur.DB.WFAG.StatusFarben.Gruen: return BitmapSourceFromImage(Properties.Resources.green_on_16); break; case WFCS.Infrastruktur.DB.WFAG.StatusFarben.Grau: return BitmapSourceFromImage(Properties.Resources.white_on_16); break; case WFCS.Infrastruktur.DB.WFAG.StatusFarben.Schwarz: return BitmapSourceFromImage(Properties.Resources.black_off_16); break; case WFCS.Infrastruktur.DB.WFAG.StatusFarben.RotFehler: default: return BitmapSourceFromImage(Properties.Resources.red_on_16); break; } } catch (Exception) { return BitmapSourceFromImage(Properties.Resources.red_on_16); } }
private static BitmapSource BitmapSourceFromImage(System.Drawing.Image img) { var memStream = new System.IO.MemoryStream();
//save the image to memStream as a png img.Save(memStream, System.Drawing.Imaging.ImageFormat.Png); //gets a decoder from this stream var decoder = new PngBitmapDecoder(memStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); return decoder.Frames[0]; }
And i'm using it like this:
<igDP:Field Name="WFKO_StatusFremdfertigung" Label="FAStOK" > <igDP:Field.Settings> <igDP:FieldSettings CellValuePresenterStyle="{StaticResource AGStatusLED}" AllowEdit="False" Width="Auto"/> </igDP:Field.Settings> </igDP:Field>
This is how it looks on screen:
This is how the print looks like:
It seems like the report just uses the first BitmapSource for all fields although the converter returns the right values.Is there a way to print the right images or is this just a bug?
Thanks,
Bastian
Hello Francis,
I've updated my converter and it seems that this solution works for me.
Thank you for your help,
Bastian,
Our developers have discovered that this issue seems to be within the WPF framework itself, independent of the Infragistics code. If the converter returns a BitmapImage rather than a BitmapFrame, then it works as expected. Attached is a sample implementing the recommended approach.
I have also sent this sample to you in the support case privately.
Please let me know if this works for you.
I am able to reproduce the issue with an XPS document, so I have logged this issue with our developers with a tracking ID of 63014.
I will create a private support case for you and link it to the Development Issue so you will be notified when the issue is addressed with a fix and/or work around.
Thanks for your help clearly describing and providing code for demonstrating the issue.
I forgot to mention that we tested this printing just with the XPS writer.
In the meantime we tested it with a regular printer and a pdf printer and the results looked like our tables on the screen. So there seems to be an issue with the XPS writer.
With your Sample I can reproduce this behaviour. When I'm using the XPS writer your sample prints 3 green circles. With a pdf printer I get the three different shapes.
Hello Bastian,
Thank you for providing your code. I tried to reproduce this behavior in a sample of my own, but I am unsuccessful so far. The printed report looks the same as the run-time display in my sample.
Please take a look at the attached sample and see if you can demonstrate the issue with it as-is, or if you need to modify it somewhat.
I will await your reply.