Beispiel #1
0
        static void Save(PlotValue plot, IPlotSerializer plotter)
        {
            var context = new SaveImageViewModel();

            context.ImageWidth  = 640;
            context.ImageHeight = 480;
            var window = new SaveImageWindow {
                DataContext = context
            };

            window.Title = Messages.SavePlotAs;

            if (!String.IsNullOrEmpty(plot.Title))
            {
                context.SelectedFile = new FileModel(plot.Title);
            }

            window.ShowDialog();

            if (context.Accepted)
            {
                var path     = context.SelectedFile.FullName;
                var filename = Path.GetFileName(path);
                var message  = String.Format(Messages.PlotSavedMessage, filename);
                var output   = new OutputViewModel
                {
                    Title   = Messages.FileCreated,
                    Message = message
                };

                using (var fs = File.Create(path))
                {
                    plotter.Save(fs, context.ImageWidth, context.ImageHeight);
                }

                output.ShowWindow();
            }
        }