Hi,
I am trying to create a report in our Silverlight application and add an image to that report but for some reason, when ever I create the Image (Infragistics.Documents.Reports.Graphics) object, my Data, Width and Height are always 0. even though I pass in a byte array with data in it.
The image I am trying to add to the report is an image of the xamWebChart.
Here's the code:
Report report = new Report(); ISection reportSection = report.AddSection(); IBand reportBand = reportSection.AddBand();//this would have some content in it.XamWebChart chart = new XamWebChart(); WriteableBitmap bitmap = new WriteableBitmap(chart, null); byte[] imageByte = bitmap.ToByteArray(); using (MemoryStream stream = new MemoryStream(imageByte)) { Image image = new Image(System.Drawing.Image.FromStream(stream), true); var reportImage = reportBand.AddImage(image); reportImage.KeepRatio = true; }
The .ToByteArray() method basically converts that WriteableBitmap into a byte[]:
public static byte[] ToByteArray(this WriteableBitmap bmp) { int[] p = bmp.Pixels; int len = p.Length << 2; byte[] result = new byte[len]; Buffer.BlockCopy(p, 0, result, 0, len); return result; }
Is there a proper way to add an image to the report in silverlight? Thanks!
Hi Connie,
You cannot create a xamWebChart and include it in report as we don't support adding custom controls to the report definition.
However, if you are lucky and the type of chart you want to create is supported by the Reporting tool you could forget about xamWebChart and use a report chart.
In that case, you'll need to trick the designer to make it bind to the structure you want. I understood you have someting like:
class ViewModel{ public IList<TableData> TableData { get; set; } public IList<ChartData> ChartData { get; set; }}
You will need to create a class with a method that returns IList<TableData> and another with a method that returns IList<ChartData> and create two ObjectDataSources in the designer and bind to those:
class MyFakeChartDataSource { IList<ChartData> GetData() { ... } }class MyFakeTableDataSource { IList<TableData> GetData() { ... } }
Then in the viewer settings you can bind those data sources to whatever you want
<ig:ClientRenderSettings.DataSources> <ig:DataSource TargetDataSource="TableDataDataSource" ItemsSource="{Binding TableData}" /> <ig:DataSource TargetDataSource="ChartDataDataSource" ItemsSource="{Binding ChartData}" /> </ig:ClientRenderSettings.DataSources>
On the other hand, there's a related thread here http://community.infragistics.com/forums/p/60149/305588.aspx. I'm not recommending following that route, but I guess you should know about it ;).
Thanks,
Andres
Andres,
By creating a report, do you mean using your .igr (report templates)? I considered creating a report template. However, I am having troubles with the DataSource for the template because we perform a RIA service query, process that data on the client side and then display it to the user using a customised XamWebChart.
How would I add a custom control into that template and set the datacontext of the table and the chart in our report to bind to different parts of the ViewModel (instead of using that Object DataSource wizard where it makes you choose a method to call)?
I hope that was clear, if it wasn't. I can try to clarify any unknowns.
Thanks!
Connie
The Infragistics.Documents is only shipped by the Reporting product to be used internally, as part of the PDF-exporting functionality, it’s not meant to be used directly.
You can create a report that includes a chart, and then export it to PDF. In order to export it, you need to include a XamReportViewer on your page and then use the Export method, for instance:
var dialog = new SaveFileDialog();
var result = dialog.ShowDialog();
if (result.HasValue && result.Value)
{
var stream = dialog.OpenFile();
// ReportViewer is the XamReportViewer instance that was inserted on the page
ReportViewer.Export(stream, "PDF");
ReportViewer.ExportCompleted += ExportCompleted;
}
Since the export process is asynchronous, you also need to close the stream once export is completed:
private void ExportCompleted(object sender, ExportCompletedEventArgs e)
ReportViewer.ExportCompleted -= ExportCompleted;
e.Stream.Close();
If you don’t want to show the Report Viewer in the page, you can set the opacity to zero, as it needs to be present in the Silverlight visual tree.
Regards,