private void SaveSvg_Click(object sender, RoutedEventArgs e) { var d = new SaveFileDialog { Filter = "Svg files (*.svg)|*.svg", DefaultExt = ".svg" }; if (true == d.ShowDialog()) { using (var s = d.OpenFile()) { var rc = new SilverlightRenderContext(new Canvas()); SvgExporter.Export(this.plot1.ActualModel, s, this.plot1.ActualWidth, this.plot1.ActualHeight, true, rc); } } }
/// <summary> /// Exports the specified plot model to a stream. /// </summary> /// <param name="model">The plot model.</param> /// <param name="stream">The stream to write to.</param> /// <param name="width">The width of the export image.</param> /// <param name="height">The height of the exported image.</param> /// <param name="background">The background.</param> public static void Export(IPlotModel model, Stream stream, double width, double height, OxyColor background) { var canvas = new Canvas { Width = width, Height = height }; if (background.IsVisible()) { canvas.Background = background.ToBrush(); } canvas.Measure(new Size(width, height)); canvas.Arrange(new Rect(0, 0, width, height)); var rc = new SilverlightRenderContext(canvas); model.Update(true); model.Render(rc, width, height); canvas.UpdateLayout(); var image = canvas.ToImage(); image.WriteToStream(stream); }
/// <summary> /// When overridden in a derived class, is invoked whenever application code or internal processes (such as a rebuilding layout pass) call <see cref="M:System.Windows.Controls.Control.ApplyTemplate" /> . In simplest terms, this means the method is called just before a UI element displays in an application. For more information, see Remarks. /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); this.grid = this.GetTemplateChild(PartGrid) as Grid; if (this.grid == null) { return; } this.canvas = new Canvas(); this.grid.Children.Add(this.canvas); this.canvas.UpdateLayout(); this.renderContext = new SilverlightRenderContext(this.canvas); this.overlays = new Canvas(); this.grid.Children.Add(this.overlays); this.zoomControl = new ContentControl(); this.overlays.Children.Add(this.zoomControl); }