예제 #1
0
        /// <summary>
        /// Helper Method for printing Chart
        /// </summary>
        /// <param name="chart">The Chart to be Printed</param>
        private static RadDocument CreateChartDocumentPart(RadChart chart)
        {
            try
            {
                RadDocument document = new RadDocument();
                Telerik.Windows.Documents.Model.Section   section   = new Telerik.Windows.Documents.Model.Section();
                Telerik.Windows.Documents.Model.Paragraph paragraph = new Telerik.Windows.Documents.Model.Paragraph();
                BitmapImage bi = new BitmapImage();

                using (MemoryStream ms = new MemoryStream())
                {
                    chart.ExportToImage(ms, new PngBitmapEncoder());
                    bi.SetSource(ms);
                }

                double imageWidth  = chart.ActualWidth;
                double imageHeight = chart.ActualHeight;

                if (imageWidth > 625)
                {
                    imageWidth  = 625;
                    imageHeight = chart.ActualHeight * imageWidth / chart.ActualWidth;
                }

                ImageInline image = new ImageInline(new WriteableBitmap(bi))
                {
                    Width = imageWidth, Height = imageHeight
                };
                paragraph.Inlines.Add(image);
                section.Blocks.Add(paragraph);
                document.Sections.Add(section);
                return(document);
            }
            catch (Exception ex)
            {
                Prompt.ShowDialog("Message: " + ex.Message + "\nStackTrace: " + Logging.StackTraceToString(ex), "Exception", MessageBoxButton.OK);
                return(null);
            }
        }