public void Save(Stream stream, object item, object options) { if (item is null) { return; } var ic = options as IImageCache; if (options is null) { return; } var exporter = new DrawingGroupXamlExporter(_serviceProvider); if (item is PageContainerViewModel page) { var dataFlow = _serviceProvider.GetService <DataFlow>(); var db = (object)page.Properties; var record = (object)page.Record; dataFlow.Bind(page.Template, db, record); dataFlow.Bind(page, db, record); var shapes = page.Layers.SelectMany(x => x.Shapes); if (shapes is { })
public void Save(Stream stream, object?item, object?options) { if (item is null) { return; } var ic = options as IImageCache; if (options is null) { return; } var exporter = new DrawingGroupXamlExporter(_serviceProvider); if (item is PageContainerViewModel page) { var dataFlow = _serviceProvider.GetService <DataFlow>(); var db = (object)page.Properties; var record = (object)page.Record; dataFlow.Bind(page.Template, db, record); dataFlow.Bind(page, db, record); var shapes = new List <BaseShapeViewModel>(); if (page.Template is { } template) { shapes.AddRange(template.Layers.SelectMany(x => x.Shapes)); } shapes.AddRange(page.Layers.SelectMany(x => x.Shapes)); { var key = page?.Name; var xaml = exporter.Create(shapes, key); if (!string.IsNullOrEmpty(xaml)) { byte[] bytes = Encoding.UTF8.GetBytes(xaml); stream.Write(bytes, 0, bytes.Length); } } } else if (item is DocumentContainerViewModel document) { throw new NotSupportedException("Saving documents as xaml drawing is not supported."); } else if (item is ProjectContainerViewModel project) { throw new NotSupportedException("Saving projects as xaml drawing is not supported."); } }
/// <inheritdoc/> public void OnCopyAsXaml(object item) { try { if (item == null) { var editor = _serviceProvider.GetService <IProjectEditor>(); var exporter = new DrawingGroupXamlExporter(_serviceProvider); var container = editor.Project.CurrentContainer; var source = editor.PageState?.SelectedShape; if (source != null) { var key = source.Name; var xaml = exporter.Create(source, key); if (!string.IsNullOrEmpty(xaml)) { editor.TextClipboard?.SetText(xaml); } return; } var sources = editor.PageState?.SelectedShapes; if (sources != null) { var xaml = exporter.Create(sources, null); if (!string.IsNullOrEmpty(xaml)) { editor.TextClipboard?.SetText(xaml); } return; } var shapes = container.Layers.SelectMany(x => x.Shapes); if (shapes != null) { var key = container?.Name; var xaml = exporter.Create(shapes, key); if (!string.IsNullOrEmpty(xaml)) { editor.TextClipboard?.SetText(xaml); } return; } } } catch (Exception ex) { _serviceProvider.GetService <ILog>()?.LogException(ex); } }