Пример #1
0
        void ExportToPng(SequenceDiagramView view)
        {
            var bodyElement   = (UIElement)view.ScrollViewer_Body.Content;
            var headerElement = (UIElement)view.ScrollViewer_Header.Content;

            var actualHeight = bodyElement.RenderSize.Height + headerElement.RenderSize.Height;
            var actualWidth  = bodyElement.RenderSize.Width;

            var renderTarget    = new RenderTargetBitmap((int)actualWidth, (int)actualHeight, 96, 96, PixelFormats.Default);
            var bodySourceBrush = new VisualBrush(bodyElement);

            var drawingVisual = new DrawingVisual();

            using (var drawingContext = drawingVisual.RenderOpen())
            {
                drawingContext.DrawRectangle(new SolidColorBrush(Colors.White), null, new Rect(new Point(0, 0), new Point(actualWidth, actualHeight)));
                drawingContext.DrawRectangle(bodySourceBrush, null, new Rect(new Point(0, 0), new Point(actualWidth, actualHeight)));
            }

            renderTarget.Render(drawingVisual);

            var saveFileDialog = new SaveFileDialog
            {
                AddExtension = true,
                DefaultExt   = ".png",
                FileName     = "sequencediagram.png",
                Filter       = "Portable Network Graphics (.png)|*.png"
            };

            if (saveFileDialog.ShowDialog() == true)
            {
                SaveAsPNG(renderTarget, saveFileDialog.FileName);
            }
        }
Пример #2
0
        public SequenceDiagramViewModel(
            IServiceControl serviceControl,
            ISettingsProvider settingsProvider,
            MessageSelectionContext selectionContext,
            DiagramLegendViewModel diagramLegend,
            CopyConversationIDCommand copyConversationIDCommand,
            CopyMessageURICommand copyMessageURICommand,
            RetryMessageCommand retryMessageCommand,
            SearchByMessageIDCommand searchByMessageIDCommand,
            ChangeSelectedMessageCommand changeSelectedMessageCommand,
            ShowExceptionCommand showExceptionCommand,
            ReportMessageCommand reportMessageCommand,
            SequenceDiagramView view)
        {
            this.serviceControl   = serviceControl;
            this.settingsProvider = settingsProvider;

            Selection = selectionContext;
            CopyConversationIDCommand    = copyConversationIDCommand;
            CopyMessageURICommand        = copyMessageURICommand;
            RetryMessageCommand          = retryMessageCommand;
            SearchByMessageIDCommand     = searchByMessageIDCommand;
            ChangeSelectedMessageCommand = changeSelectedMessageCommand;
            ShowExceptionCommand         = showExceptionCommand;
            ReportMessageCommand         = reportMessageCommand;
            OpenLink             = this.CreateCommand(arg => new NetworkOperations().Browse(SequenceDiagramDocumentationUrl));
            ExportDiagramCommand = this.CreateCommand(() => ExportToPng(view), m => m.HasItems);
            DiagramLegend        = diagramLegend;
            DiagramItems         = new DiagramItemCollection();
            HeaderItems          = new DiagramItemCollection();

            settings = settingsProvider.GetSettings <SequenceDiagramSettings>();

            ShowLegend = settings.ShowLegend;
        }
 protected override void OnViewLoaded(object view)
 {
     base.OnViewLoaded(view);
     this.view = (SequenceDiagramView)view;
 }