How to Print a Graph with Silverlight 4
Tips & TricksSummary
This article shows how the contents of a CanvasControl (e.g. a graph) can be printed in yFiles for Silverlight together with Silverlight 4.
Description
Since Silverlight 4, printing is supported by the Silverlight platform. yFiles for Silverlight versions before 2.0 that target the Silverlight 3 environment, offer no printing support out of the box. However, it is easily possible to use the printing support in Silverlight 4 together with these versions of yFiles for Silverlight.
The following example code (yFiles for Silverlight versions before 2.0) prints the current contents of the graph control.ContextConfigurator cc = new ContextConfigurator(graphControl.Viewport, graphControl.Zoom);
Transform transform;
Geometry clip;
IRenderContext renderContext = cc.Setup(graphControl, out transform, out clip);
FrameworkElement content = graphControl.CreateVisualContent(renderContext);
double w = graphControl.GetContentHost().ActualWidth;
double h = graphControl.GetContentHost().ActualHeight;
content.Measure(new Size(w, h));
content.Arrange(new Rect(0, 0, w, h));
PrintDocument pd = new PrintDocument();
pd.PrintPage += delegate(object o, PrintPageEventArgs args) {
args.PageVisual = new CanvasContainer()
{Children = {content}, RenderTransform = transform};
args.HasMorePages = false;
};
pd.Print("yFiles Print Document");
Categories this article belongs to:
yFiles for Silverlight > yFiles for Silverlight Viewer > Input and Output
Applies to:
yFiles for Silverlight: 1.0, 1.0.1
Keywords:
printer - printing - PrintDocument - ContextConfigurator - Silverlight 4