private void Annotation_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName.Equals("Mode")) { TextAnnotationViewModel annotaiton = sender as TextAnnotationViewModel; if (annotaiton != null && annotaiton.Mode == ContentEditorMode.View) { TextBlock textblock = new TextBlock(); textblock.RenderTransformOrigin = new Point(0.5, 0.5); textblock.Width = this.UnitWidth; textblock.Text = annotaiton.Text; textblock.TextWrapping = annotaiton.TextWrapping; textblock.FontStyle = annotaiton.FontStyle; textblock.FontSize = annotaiton.FontSize; textblock.Foreground = annotaiton.Foreground; textblock.FontWeight = annotaiton.FontWeight; if (annotaiton.FontFamily != null) { textblock.FontFamily = annotaiton.FontFamily; } textblock.HorizontalAlignment = annotaiton.HorizontalAlignment; textblock.VerticalAlignment = annotaiton.VerticalAlignment; textblock.TextAlignment = annotaiton.TextHorizontalAlignment; textblock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); this.UnitHeight = Math.Max(96, textblock.DesiredSize.Height); } } }
//Create and Add Connectors private void AddConnector(NodeViewModel sourceNode, NodeViewModel targetNode, string text) { TextAnnotationViewModel textannotation = new TextAnnotationViewModel(); textannotation.Text = manager.GetString(text); textannotation.ReadOnly = true; textannotation.RotationReference = Syncfusion.UI.Xaml.Diagram.RotationReference.Page; if (text == "Yes") { //Setting the margin to the text textannotation.Margin = new Thickness(10, 0, 0, 0); } else { textannotation.Margin = new Thickness(0, 10, 0, 0); } ConnectorViewModel connector = new ConnectorViewModel(); connector.SourceNode = sourceNode; connector.TargetNode = targetNode; connector.Annotations = new ObservableCollection <IAnnotation>() { textannotation }; (diagramcontrol.Connectors as ObservableCollection <ConnectorViewModel>).Add(connector); }
/// <summary> /// Method to create Node /// </summary> /// <param name="offsetx"></param> /// <param name="shape"></param> /// <param name="annotation"></param> /// <param name="constraints"></param> private void CreateNode(double offsetx, string shape, string annotation, string constraints) { TextAnnotationViewModel anno = new TextAnnotationViewModel() { Text = annotation, }; NodeViewModel node = new NodeViewModel() { OffsetX = offsetx, OffsetY = 250, UnitHeight = 100, UnitWidth = 100, Shape = resourceDictionary[shape], Annotations = new AnnotationCollection() { anno, }, ShapeStyle = View.Resources["DefaultStyle"] as Style, }; if (constraints.Equals("Selection")) { node.Constraints = node.Constraints.Remove(NodeConstraints.Selectable); } else if (constraints.Equals("Drag")) { node.Constraints = node.Constraints.Remove(NodeConstraints.InheritDraggable); } else if (constraints.Equals("Resize")) { node.Constraints = node.Constraints.Remove(NodeConstraints.InheritResizable); } else if (constraints.Equals("Rotate")) { node.ID = "Rotate"; node.RotateAngle = 45; node.Constraints = node.Constraints.Remove(NodeConstraints.InheritRotatable); } else if (constraints.Equals("Edit")) { anno.Constraints = anno.Constraints.Remove(AnnotationConstraints.InheritEditable | AnnotationConstraints.Editable); } else if (constraints.Equals("Delete")) { node.Constraints = node.Constraints.Remove(NodeConstraints.Delete); } (Nodes as NodeCollection).Add(node); }
/// <summary> /// Method to create Connectors /// </summary> /// <param name="point1"></param> /// <param name="point2"></param> /// <param name="annotation"></param> /// <param name="constraints"></param> private void CreateConnector(Point point1, Point point2, string annotation, string constraints) { TextAnnotationViewModel anno = new TextAnnotationViewModel() { Text = annotation, Margin = new Thickness(0, 10, 30, 0), }; ConnectorViewModel con = new ConnectorViewModel() { SourcePoint = point1, TargetPoint = point2, Annotations = new AnnotationCollection() { anno, }, }; if (constraints.Equals("Selection")) { con.Constraints = con.Constraints.Remove(ConnectorConstraints.Selectable); } else if (constraints.Equals("Drag")) { con.Constraints = con.Constraints.Add(ConnectorConstraints.Draggable); } else if (constraints.Equals("Delete")) { con.Constraints = con.Constraints.Remove(ConnectorConstraints.Delete); } else if (constraints.Equals("EndThumb")) { con.Constraints = con.Constraints.Remove(ConnectorConstraints.EndThumbs); } else if (constraints.Equals("EndDraggable")) { con.Constraints = con.Constraints.Remove(ConnectorConstraints.EndDraggable); } else if (constraints.Equals("SegmentThumb")) { con.Constraints = con.Constraints.Remove(ConnectorConstraints.SegmentThumbs); } (Connectors as ConnectorCollection).Add(con); }
protected override void OnPropertyChanged(string name) { base.OnPropertyChanged(name); switch (name) { case "ThemeStyleId": if (this.Info != null && (this.Info as INodeInfo).OutConnectors != null && (this.Info as INodeInfo).OutConnectors.Count() > 0) { Style connectorGeometryStyle = SetDefultConnectorGeometryStyle(); Style targetDecoratorStyle = SetDefaultTargetDecoratorStyle(); foreach (IConnector connector in (this.Info as INodeInfo).OutConnectors.ToList()) { connector.ConnectorGeometryStyle = connectorGeometryStyle; connector.TargetDecoratorStyle = targetDecoratorStyle; } } break; case "Children": Children.CollectionChanged += (s, e) => { if (Children.Count() > 0) { HasChidren = true; } else { HasChidren = false; } }; break; case "Annotations": if (Annotations != null) { if ((Annotations as AnnotationCollection).Count > 0) { if ((Annotations as AnnotationCollection)[0] is TextAnnotationViewModel) { TextAnnotationViewModel textAnnotation = (Annotations as AnnotationCollection)[0] as TextAnnotationViewModel; textAnnotation.PropertyChanged += Annotation_PropertyChanged; } } else { (Annotations as AnnotationCollection).CollectionChanged += (s, e) => { if (e.NewItems != null && e.NewItems[0] is TextAnnotationViewModel) { (e.NewItems[0] as TextAnnotationViewModel).EditTemplate = GetEditTemplate(); (e.NewItems[0] as TextAnnotationViewModel).PropertyChanged += Annotation_PropertyChanged; } }; } } //if (Annotations != null && (Annotations as AnnotationCollection).Count > 0) //{ // if ((Annotations as AnnotationCollection)[0] is TextAnnotationViewModel) // { // TextAnnotationViewModel textAnnotation = (Annotations as AnnotationCollection)[0] as TextAnnotationViewModel; // textAnnotation.PropertyChanged += Annotation_PropertyChanged; // } //} break; } }
protected override void OnPropertyChanged(string name) { base.OnPropertyChanged(name); switch (name) { case "ShapeStyle": DecodeStyle(this.ShapeStyle); break; case "Fill": ApplyStyle(); break; case "Stroke": ApplyStyle(); break; case "ThemeStyleId": if (!string.IsNullOrEmpty(ShapeName) && (ShapeName.Equals("Line") || ShapeName.Equals("Freehand"))) { TextAnnotationViewModel textAnnotaiton = Annotations != null ? (Annotations as AnnotationCollection)[0] as TextAnnotationViewModel : null; if (textAnnotaiton != null) { textAnnotaiton.Foreground = Brushes.Black; } } if (this.Info != null && (this.Info as INodeInfo).OutConnectors != null && (this.Info as INodeInfo).OutConnectors.Count() > 0) { Style connectorGeometryStyle = SetDefultConnectorGeometryStyle(); Style targetDecoratorStyle = SetDefaultTargetDecoratorStyle(); foreach (IConnector connector in (this.Info as INodeInfo).OutConnectors.ToList()) { connector.ConnectorGeometryStyle = connectorGeometryStyle; connector.TargetDecoratorStyle = targetDecoratorStyle; } } break; case "Children": Children.CollectionChanged += (s, e) => { if (Children.Count() > 0) { HasChidren = true; } else { HasChidren = false; } }; break; case "Annotations": if (Annotations != null) { if (Annotations != null) { if ((Annotations as AnnotationCollection).Count > 0) { if ((Annotations as AnnotationCollection)[0] is TextAnnotationViewModel) { TextAnnotationViewModel textAnnotation = (Annotations as AnnotationCollection)[0] as TextAnnotationViewModel; textAnnotation.PropertyChanged += Annotation_PropertyChanged; } } else { (Annotations as AnnotationCollection).CollectionChanged += (s, e) => { if (e.NewItems != null && e.NewItems[0] is TextAnnotationViewModel) { (e.NewItems[0] as TextAnnotationViewModel).EditTemplate = GetEditTemplate(); (e.NewItems[0] as TextAnnotationViewModel).PropertyChanged += Annotation_PropertyChanged; } }; } } } //if (Annotations != null && (Annotations as AnnotationCollection).Count > 0) //{ // if ((Annotations as AnnotationCollection)[0] is TextAnnotationViewModel) // { // TextAnnotationViewModel textAnnotation = (Annotations as AnnotationCollection)[0] as TextAnnotationViewModel; // textAnnotation.PropertyChanged += Annotation_PropertyChanged; // } //} break; case "ShapeName": TextAnnotationViewModel annotation = Annotations != null ? (Annotations as AnnotationCollection)[0] as TextAnnotationViewModel : null; if (!string.IsNullOrEmpty(ShapeName) && ShapeName.Equals("Line")) { Shape = null; ContentTemplate = GetLineTempalte(); Content = this; if (annotation != null) { annotation.TextVerticalAlignment = VerticalAlignment.Stretch; annotation.Foreground = Brushes.Black; } if (this.Ports != null) { if ((this.Info as INodeInfo).InConnectors != null && (this.Info as INodeInfo).InConnectors.Count() > 0) { foreach (IConnector connector in (this.Info as INodeInfo).InConnectors.ToList()) { if (this.RenderedDirection == RootChildDirection.Left) { connector.TargetPort = (this.Ports as ObservableCollection <IPort>)[3]; } else if (this.RenderedDirection == RootChildDirection.Right) { connector.TargetPort = (this.Ports as ObservableCollection <IPort>)[0]; } } } if ((this.Info as INodeInfo).OutConnectors != null && (this.Info as INodeInfo).OutConnectors.Count() > 0) { foreach (IConnector connector in (this.Info as INodeInfo).OutConnectors.ToList()) { if (this.RenderedDirection == RootChildDirection.Left) { connector.SourcePort = (this.Ports as ObservableCollection <IPort>)[0]; } else if (this.RenderedDirection == RootChildDirection.Right) { connector.SourcePort = (this.Ports as ObservableCollection <IPort>)[3]; } } } } } else { Shape = GetShapeData(ShapeName); ContentTemplate = null; Content = null; if (annotation != null) { annotation.TextVerticalAlignment = VerticalAlignment.Center; if (!string.IsNullOrEmpty(ShapeName) && ShapeName.Equals("Freehand")) { annotation.Foreground = Brushes.Black; } else { OnThemeStyleIdChanged(); } } if (!string.IsNullOrEmpty(ShapeName) && ShapeName.Equals("Wave")) { if (this.Ports != null && this.Info != null) { if ((this.Info as INodeInfo).InConnectors != null && (this.Info as INodeInfo).InConnectors.Count() > 0) { foreach (IConnector connector in (this.Info as INodeInfo).InConnectors.ToList()) { if (this.RenderedDirection == RootChildDirection.Left) { connector.TargetPort = (this.Ports as ObservableCollection <IPort>)[2]; } else if (this.RenderedDirection == RootChildDirection.Right) { connector.TargetPort = (this.Ports as ObservableCollection <IPort>)[1]; } } } if ((this.Info as INodeInfo).OutConnectors != null && (this.Info as INodeInfo).OutConnectors.Count() > 0) { foreach (IConnector connector in (this.Info as INodeInfo).OutConnectors.ToList()) { if (this.RenderedDirection == RootChildDirection.Left) { connector.SourcePort = (this.Ports as ObservableCollection <IPort>)[1]; } else { connector.SourcePort = (this.Ports as ObservableCollection <IPort>)[2]; } } } } } else { if (this.Info != null) { if ((this.Info as INodeInfo).InConnectors != null && (this.Info as INodeInfo).InConnectors.Count() > 0) { foreach (IConnector connector in (this.Info as INodeInfo).InConnectors.ToList()) { connector.TargetPort = null; } } if ((this.Info as INodeInfo).OutConnectors != null && (this.Info as INodeInfo).OutConnectors.Count() > 0) { foreach (IConnector connector in (this.Info as INodeInfo).OutConnectors.ToList()) { connector.SourcePort = null; } } } } } break; } }