/// <summary> /// Represents the addimagenode command execution. /// </summary> /// <param name="param"> /// The param. /// </param> public void OnAddImageNodeCommand(object param) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png"; if (openFileDialog.ShowDialog() == true) { BitmapImage bitmap = new BitmapImage(new Uri(openFileDialog.FileName, UriKind.Absolute)); double offX = this.ScrollSettings.ScrollInfo.HorizontalOffset / this.ScrollSettings.ScrollInfo.CurrentZoom + this.ScrollSettings.ScrollInfo.ViewportWidth / 2 - bitmap.Width * this.ScrollSettings.ScrollInfo.CurrentZoom / 2; double offY = this.ScrollSettings.ScrollInfo.VerticalOffset / this.ScrollSettings.ScrollInfo.CurrentZoom + this.ScrollSettings.ScrollInfo.ViewportHeight / 2 - bitmap.Height * this.ScrollSettings.ScrollInfo.CurrentZoom / 2; NodeVM nodevm = new NodeVM { OffsetX = offX, OffsetY = offY, Content = new Image { Stretch = Stretch.Fill, Source = bitmap } }; (this.Nodes as ObservableCollection <NodeVM>).Add(nodevm); } }
async public void OnCapturesCommand(object param) { MediaCapture takePhotoManager = new MediaCapture(); await takePhotoManager.InitializeAsync(); ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg(); IStorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync( "Photo.jpg", CreationCollisionOption.GenerateUniqueName); await takePhotoManager.CapturePhotoToStorageFileAsync(imgFormat, file); //Windows.Storage.StorageFile file = await cameraUI.CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo); if (file != null) { IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); BitmapImage bitmap = new BitmapImage(); bitmap.SetSource(fileStream); IGraphInfo graph = this.Info as IGraphInfo; NodeVM node = new NodeVM(); node.OffsetX = ((this.Info as IGraph).ScrollSettings.ScrollInfo.ViewportWidth) / 2; node.OffsetY = ((this.Info as IGraph).ScrollSettings.ScrollInfo.ViewportHeight) / 2; node.UnitHeight = 100; node.UnitWidth = 100; node.Content = new Image() { Source = bitmap, Stretch = Stretch.Fill }; (Nodes as ObservableCollection <NodeVM>).Add(node); } }
async private void Onuploadcommand(object obj) { var picker = new FileOpenPicker(); picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; picker.ViewMode = PickerViewMode.Thumbnail; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); var file = await picker.PickSingleFileAsync(); if (file == null) { return; } var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); BitmapImage image = new BitmapImage(); image.SetSource(stream); IGraphInfo graph = this.Info as IGraphInfo; NodeVM node = new NodeVM(); node.OffsetX = ((this.Info as IGraph).ScrollSettings.ScrollInfo.ViewportWidth) / 2; node.OffsetY = ((this.Info as IGraph).ScrollSettings.ScrollInfo.ViewportHeight) / 2; node.UnitHeight = 100; node.UnitWidth = 100; node.Content = new Image() { Source = image, Stretch = Stretch.Fill }; (Nodes as ObservableCollection <NodeVM>).Add(node); }
void graph_GetDrawType(object sender, DrawTypeEventArgs args) { if (IsDrawTextNode) { NodeVM node = new NodeVM(); node.UnitWidth = 150; node.UnitHeight = 50; node.Annotations = new List <IAnnotation>(); LabelVM label = new LabelVM(); label.Mode = ContentEditorMode.Edit; label.UnitWidth = 100; label.UnitHeight = 100; label.Content = ""; (node.Annotations as List <IAnnotation>).Add(label); args.DrawItem = node; node.PropertyChanged += (s, e) => { if (e.PropertyName.Equals("IsSelected")) { INode n = s as INode; if (n.IsSelected) { (this.SelectedItems as SelectorVM).SelectorConstraints &= ~SelectorConstraints.QuickCommands; } else { (this.SelectedItems as SelectorVM).SelectorConstraints = SelectorConstraints.Default; foreach (IAnnotation annotaiton in n.Annotations as List <IAnnotation> ) { if (annotaiton.Content != null) { if (string.IsNullOrEmpty(annotaiton.Content.ToString())) { NodeCollection.Remove(s as NodeVM); break; } } } } } }; } else if (this.Shape.Equals("Rectangle")) { args.DrawItem = new System.Windows.Shapes.Rectangle() { StrokeThickness = 1.0, Stroke = new SolidColorBrush(Colors.Black), Fill = new SolidColorBrush(Colors.White), Stretch = Stretch.Fill }; } else if (this.Shape.Equals("Ellipse")) { args.DrawItem = new System.Windows.Shapes.Ellipse() { StrokeThickness = 1.0, Stroke = new SolidColorBrush(Colors.Black), Fill = new SolidColorBrush(Colors.White) }; } //else if (this.Shape.Equals("Line")) //{ //} }
/// <summary> /// The graph_ get draw type. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="args"> /// The args. /// </param> private void graph_GetDrawType(object sender, DrawTypeEventArgs args) { if (this.IsDrawTextNode) { NodeVM node = new NodeVM(); node.UnitWidth = 150; node.UnitHeight = 50; node.Annotations = new List <IAnnotation>(); LabelVM label = new LabelVM(); label.Mode = ContentEditorMode.Edit; label.UnitWidth = 100; label.UnitHeight = 100; label.Content = string.Empty; (node.Annotations as List <IAnnotation>).Add(label); args.DrawItem = node; node.PropertyChanged += (s, e) => { if (e.PropertyName.Equals("IsSelected")) { INode n = s as INode; if (n.IsSelected) { (this.SelectedItems as SelectorVM).SelectorConstraints &= ~SelectorConstraints.QuickCommands; } } }; } else if (this.Shape.Equals("Rectangle")) { args.DrawItem = new Rectangle { StrokeThickness = 1.0, Stroke = new SolidColorBrush(Colors.Black), Fill = new SolidColorBrush(Colors.White), Stretch = Stretch.Fill }; } else if (this.Shape.Equals("Ellipse")) { args.DrawItem = new Ellipse { StrokeThickness = 1.0, Stroke = new SolidColorBrush(Colors.Black), Fill = new SolidColorBrush(Colors.White) }; } }
void SelectedSymbol_DoubleTapped(object sender, Windows.UI.Xaml.Input.DoubleTappedRoutedEventArgs e) { if (this.SelectedDiagram.SelectedItems != null && ((this.SelectedDiagram.SelectedItems as SelectorVM).Nodes as ICollection <object>).Count > 0) { ((this.SelectedDiagram.SelectedItems as SelectorVM).Nodes as ICollection <object>).Clear(); } NodeVM node = new NodeVM(); IGraph graph = this.SelectedDiagram.Info as IGraph; node.OffsetX = graph.ScrollSettings.ScrollInfo.ViewportWidth / 2; node.OffsetY = graph.ScrollSettings.ScrollInfo.ViewportHeight / 2; node.UnitWidth = 100; node.UnitHeight = 100; node.Content = Stencil.SelectedSymbol.Content; node.ContentTemplate = Stencil.SelectedSymbol.ContentTemplate; node.IsSelected = true; this.SelectedDiagram.NodeCollection.Add(node); e.Handled = true; }