예제 #1
0
        public bool ExportCurrentMap(object ownerViewModel)
        {
            FileDialogResult result = _dialogService.ShowSaveFileDialog("Export Map", ownerViewModel, new FileType("PNG image", ".png"));

            if (result.IsValid)
            {
                GMapControl mapControl = System.Windows.Application.Current.MainWindow.FindVisualDescendants <GMapControl>().FirstOrDefault();
                if (mapControl == null)
                {
                    throw new InvalidOperationException();
                }

                var encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create((BitmapSource)mapControl.ToImageSource()));
                using (var file = File.Create(result.FileName))
                    encoder.Save(file);
                return(true);
            }
            return(false);
        }