public BitmapSource CreateImage(double dpi, double margin = 0, CancellationToken cancellationToken = default(CancellationToken), IIncrementalProgress progress = null, IProgress <int> maxProgress = null) { using (var diagramImageViewModel = new DiagramImageViewModel(_diagramNodeViewModels, _diagramConnectorViewModels, _diagramRect, margin)) { var diagramImageControl = new DiagramImageControl(_resourceDictionary) { DataContext = diagramImageViewModel }; ApplyVisualProperties(diagramImageControl, _diagramStyleProvider); diagramImageControl.EnsureUpToDate(); var bounds = new Rect(0, 0, diagramImageControl.ActualWidth, diagramImageControl.ActualHeight); return(UiToBitmapRenderer.RenderUiElementToBitmap(diagramImageControl, bounds, dpi, cancellationToken, progress, maxProgress)); } }
public BitmapSource CreateImage( double dpi, double margin = 0, CancellationToken cancellationToken = default, IIncrementalProgress progress = null, IProgress <int> maxProgress = null) { using (var diagramImageViewModel = new DiagramImageViewModel(_diagramNodeViewModels, _diagramConnectorViewModels, _diagramRect, margin)) { var diagramImageControl = new DiagramImageControl(_diagramStyleProvider.AdditionalResourceDictionary) { DataContext = diagramImageViewModel }; ApplyVisualProperties(diagramImageControl, _diagramStyleProvider); diagramImageControl.EnsureUpToDate(); // Uncomment this for troubleshooting the generated image! //var window = new Window { Content = diagramImageControl }; //window.ShowDialog(); var bounds = new Rect(0, 0, diagramImageControl.ActualWidth, diagramImageControl.ActualHeight); return(UiToBitmapRenderer.RenderUiElementToBitmap(diagramImageControl, bounds, dpi, cancellationToken, progress, maxProgress)); } }