public DiagramVM(bool IsCustomVM) { _isCustomVM = IsCustomVM; Nodes = new ObservableCollection <NodeVM>(); Connectors = new ObservableCollection <ConnectorVM>(); Groups = new ObservableCollection <GroupVM>(); SelectedItems = new SelectorVM(this); Select = new Command(param => IsSelected = true); FirstLoad = new Command(OnViewLoaded); SnapSettings = new SnapSettings() { SnapConstraints = SnapConstraints.All, SnapToObject = SnapToObject.All }; PageSettings = new PageVM(); (PageSettings as PageVM).InitDiagram(this); this.CommandManager.View = (Control)Window.Current.Content; }
public async Task Save() { try { IGraphInfo graph = this.Info as IGraphInfo; PageVM page = PageSettings as PageVM; if (graph != null && (this.Info as IGraph).ScrollSettings.ScrollInfo != null) { page.HOffset = (this.Info as IGraph).ScrollSettings.ScrollInfo.HorizontalOffset; page.VOffset = (this.Info as IGraph).ScrollSettings.ScrollInfo.VerticalOffset; page.Scale = (this.Info as IGraph).ScrollSettings.ScrollInfo.CurrentZoom; _file = await installedLocation.CreateFileAsync(_file.Name, CreationCollisionOption.ReplaceExisting); using (Stream stream = await _file.OpenStreamForWriteAsync()) { graph.Save(stream); } _isValidXml = true; } } catch { } }
/// <summary> /// The on view loaded. /// </summary> /// <param name="param"> /// The param. /// </param> private async void OnViewLoaded(object param) { IGraphInfo graph = this.Info as IGraphInfo; graph.ItemAdded += this.DiagramVM_ItemAdded; graph.ItemDropEvent += this.Graph_ItemDropEvent; graph.ItemDeleted += this.DiagramVM_ItemDeleted; graph.GetDrawType += this.graph_GetDrawType; graph.NodeChangedEvent += this.Graph_NodeChangedEvent; await this.Load(); PageVM page = this.PageSettings as PageVM; if (this._isValidXml) { graph.Commands.Zoom.Execute(new ZoomPositionParameter { ZoomTo = page.Scale }); this.ScrollSettings.ScrollInfo.PanTo(new Point(page.HOffset, page.VOffset)); } this.IsBusy = Visibility.Collapsed; }
private async void OnViewLoaded(object param) { IGraphInfo graph = Info as IGraphInfo; graph.ItemAdded += DiagramVM_ItemAdded; graph.ItemDropEvent += Graph_ItemDropEvent; graph.ItemDeleted += DiagramVM_ItemDeleted; graph.SymbolDroppingEvent += graph_SymbolDroppingEvent; graph.GetDrawType += graph_GetDrawType; graph.NodeChangedEvent += Graph_NodeChangedEvent; await Load(); PageVM page = PageSettings as PageVM; if (_isValidXml) { graph.Commands.Zoom.Execute( new ZoomPositionParamenter() { ZoomTo = page.Scale }); graph.ScrollInfo.PanTo(new Point(page.HOffset, page.VOffset)); } //else //{ // await Save(); // (Info as IGraphInfo).Commands.FitToPage.Execute( // new FitToPageParameter // { // FitToPage = FitToPage.FitToPage, // Margin = new Thickness(20) // } // ); // this.Save(); //} IsBusy = Visibility.Collapsed; }
public async Task Save(string savedpath) { //try //{ IGraphInfo graph = this.Info as IGraphInfo; PageVM page = PageSettings as PageVM; if (graph != null && graph.ScrollInfo != null) { page.HOffset = graph.ScrollInfo.HorizontalOffset; page.VOffset = graph.ScrollInfo.VerticalOffset; page.Scale = graph.ScrollInfo.CurrentZoom; _file = savedpath; using (FileStream fileStream = File.OpenWrite(_file)) { graph.Save(fileStream); } _isValidXml = true; } // } //catch //{ } }
async public void OnPrintCommand(object param) { PageVM page = SelectedDiagram.PageSettings as PageVM; PrintingService print = SelectedDiagram.PrintingService as PrintingService; print.PrintMargin = page.PrintMargin; print.Height = page.PageHeight; print.Width = page.PageWidth; switch (page.SelectedFormat) { case PageSize.A0: print.PrintMediaSize = PrintMediaSize.IsoA0; break; case PageSize.A1: print.PrintMediaSize = PrintMediaSize.IsoA1; break; case PageSize.A2: print.PrintMediaSize = PrintMediaSize.IsoA2; break; case PageSize.A3: print.PrintMediaSize = PrintMediaSize.IsoA3; break; case PageSize.A4: print.PrintMediaSize = PrintMediaSize.IsoA4; break; case PageSize.A5: print.PrintMediaSize = PrintMediaSize.IsoA5; break; case PageSize.Folio: print.PrintMediaSize = PrintMediaSize.OtherMetricFolio; break; case PageSize.Ledger: print.PrintMediaSize = PrintMediaSize.NorthAmericaTabloid; break; case PageSize.Legal: print.PrintMediaSize = PrintMediaSize.NorthAmericaLegal; break; case PageSize.Letter: print.PrintMediaSize = PrintMediaSize.NorthAmericaLetter; break; } if (page.PageOrientation == PageOrientation.Landscape) { print.PrintOrientation = PrintOrientation.Landscape; } else { print.PrintOrientation = PrintOrientation.Portrait; } print.UnregisterForPrinting(); print.RegisterForPrinting(); //if (Windows.Graphics.Printing.PrintManager. { try { // Show print UI await Windows.Graphics.Printing.PrintManager.ShowPrintUIAsync(); } catch { // Printing cannot proceed at this time ContentDialog noPrintingDialog = new ContentDialog() { Title = "Printing error", Content = "\nSorry, printing can' t proceed at this time.", PrimaryButtonText = "OK" }; await noPrintingDialog.ShowAsync(); } } }
//StorageFile file, public DiagramVM(string file, bool isValidXml) { _isValidXml = isValidXml; _file = file; Nodes = new ObservableCollection <NodeVM>(); Connectors = new ObservableCollection <ConnectorVM>(); Groups = new ObservableCollection <GroupVM>(); SelectedItems = new SelectorVM(this); PortVisibility = PortVisibility.MouseOverOnConnect; Select = new Command(param => IsSelected = true); FirstLoad = new Command(OnViewLoaded); HistoryManager = new customManager(); SnapSettings = new SnapSettings() { SnapConstraints = SnapConstraints.All, SnapToObject = SnapToObject.All }; PreviewSettings = new PreviewSettings() { PreviewMode = PreviewMode.Preview }; PageSettings = new PageVM(); (PageSettings as PageVM).InitDiagram(this); this.HorizontalRuler = new Ruler() { Orientation = Orientation.Horizontal }; this.VerticalRuler = new Ruler() { Orientation = Orientation.Vertical }; //OffPageBackground = new SolidColorBrush(new Color() { A = 0xFF, R = 0xEC, G = 0xEC, B = 0xEC }); //OffPageBackground = new SolidColorBrush(new Color() { A = 0xFF, R = 0x2D, G = 0x2D, B = 0x2D }); InitLocation(); PrintingService = new PrintingService(); ExportSettings = new ExportSettings() { ImageStretch = Stretch.Uniform, ExportMode = ExportMode.PageSettings }; #if SyncfusionFramework4_5_1 ExportSettings = new ExportSettings() { ImageStretch = Stretch.Uniform, ExportMode = ExportMode.PageSettings }; PrintingService = new PrintingService(); #endif FlipCommand = new Command(OnFlipCommand); ExportCommand = new Command(OnExportCommand); PrintCommand = new Command(OnPrintCommand); Captures = new Command(OnCapturesCommand); ClearDiagram = new Command(OnClearCommand); Upload = new Command(Onuploadcommand); Draw = new Command(OnDrawCommand); SingleSelect = new Command(OnSingleSelectCommand); SelectAll = new Command(OnSelectAllCommand); Manipulate = new Command(OnManipulateCommand); LoadExt = new Command(OnLoadExt); AddImageNode = new Command(OnAddImageNodeCommand); PageOrientationCommand = new Command(OnPageOrientationCommand); PageSizeCommand = new Command(OnPageSizeCommand); ConnectTypeCommand = new Command(OnConnectTypeCommand); RotateTextCommand = new Command(OnRotateTextCommand); //SelectTextCommand = new Command(OnSelectTextCommand); SizeandPositionCommand = new Command(OnSizeandPositionCommand); PanZoomCommand = new Command(OnPanZoomCommand); FitToWidthCommand = new Command(OnFitToWidthCommand); FitToPageCommand = new Command(OnFitToPageCommand); //Tool = Tool.ZoomPan | Tool.SingleSelect; ; //ConnectorVM c = new ConnectorVM() //{ // SourcePoint = new Point(100, 100), // TargetPoint = new Point(300, 300) //}; //(this.ConnectorCollection as ICollection<ConnectorVM>).Add(c); }
public void OnPrintCommand(object param) { #if SyncfusionFramework4_5_1 PageVM page = SelectedDiagram.PageSettings as PageVM; PrintingService print = SelectedDiagram.PrintingService; print.PrintMargin = page.PrintMargin; switch (page.SelectedFormat) { case PageSize.A0: print.PrintMediaSize = PrintMediaSize.IsoA0; break; case PageSize.A1: print.PrintMediaSize = PrintMediaSize.IsoA1; break; case PageSize.A2: print.PrintMediaSize = PrintMediaSize.IsoA2; break; case PageSize.A3: print.PrintMediaSize = PrintMediaSize.IsoA3; break; case PageSize.A4: print.PrintMediaSize = PrintMediaSize.IsoA4; break; case PageSize.A5: print.PrintMediaSize = PrintMediaSize.IsoA5; break; case PageSize.Folio: print.PrintMediaSize = PrintMediaSize.OtherMetricFolio; break; case PageSize.Ledger: print.PrintMediaSize = PrintMediaSize.NorthAmericaTabloid; break; case PageSize.Legal: print.PrintMediaSize = PrintMediaSize.NorthAmericaLegal; break; case PageSize.Letter: print.PrintMediaSize = PrintMediaSize.NorthAmericaLetter; break; } if (page.PageOrientation == PageOrientation.Landscape) { print.PrintOrientation = PrintOrientation.Landscape; } else { print.PrintOrientation = PrintOrientation.Portrait; } print.UnregisterForPrinting(); print.RegisterForPrinting(); //await Windows.Graphics.Printing.PrintManager.ShowPrintUIAsync(); #endif }