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
585
Printing XamDataGrid with Bitmaps
posted

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