/// <summary> /// Create and add the nodes. /// </summary> /// <param name="id">ID of the Node</param> /// <param name="offsetx">Offset-x value of the node.</param> /// <param name="offsety">Offset-y value of the node.</param> /// <param name="text">Text to the node.</param> private void CreateNodes(string id, double offsetx, double offsety, string text) { CustomNodeViewModel node = new CustomNodeViewModel() { ID = id, UnitHeight = 100, UnitWidth = 100, OffsetX = offsetx, OffsetY = offsety, Shape = new EllipseGeometry() { RadiusX = 10, RadiusY = 10 }, Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#37909A")), Annotations = new ObservableCollection <IAnnotation>() { new TextAnnotationViewModel() { Text = text, FontSize = 15, Foreground = new SolidColorBrush(Colors.White), } }, }; //Add Node to Nodes property of the Diagram (this.Nodes as ObservableCollection <CustomNodeViewModel>).Add(node); }
/// <summary> /// Command to item added event. /// </summary> /// <param name="parameter">ItemAddedEventArgs</param> private void OnItemAddedCommandExecute(object parameter) { if (SelectedTheme.Equals("None")) { CustomNodeViewModel node = (parameter as ItemAddedEventArgs).Item as CustomNodeViewModel; if (ShapeName.Equals("stroke")) { node.ContentTemplate = null; (node as CustomNodeViewModel).Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#37909A")); (node as CustomNodeViewModel).StrokeColor = new SolidColorBrush(Colors.Black); (node as CustomNodeViewModel).StrokeThickess = 2; (node as CustomNodeViewModel).StrokeDash = double.MaxValue; } else if (ShapeName.Equals("strokeDash")) { node.ContentTemplate = null; (node as CustomNodeViewModel).Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#37909A")); (node as CustomNodeViewModel).StrokeColor = new SolidColorBrush(Colors.Black); (node as CustomNodeViewModel).StrokeThickess = 2; (node as CustomNodeViewModel).StrokeDash = 2; } else if (ShapeName.Equals("gradiant")) { node.ContentTemplate = null; (node as CustomNodeViewModel).Fill = LinearGradientBrush(); (node as CustomNodeViewModel).StrokeColor = new SolidColorBrush(Colors.Black); (node as CustomNodeViewModel).StrokeThickess = 2; (node as CustomNodeViewModel).StrokeDash = 2; } else if (ShapeName.Equals("shadow")) { node.ContentTemplate = View.Resources["ShadowNode"] as DataTemplate; (node as CustomNodeViewModel).StrokeColor = new SolidColorBrush(Colors.Black); (node as CustomNodeViewModel).StrokeThickess = 2; (node as CustomNodeViewModel).StrokeDash = 2; } else { node.ContentTemplate = null; (node as CustomNodeViewModel).Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#37909A")); (node as CustomNodeViewModel).StrokeColor = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#37909A")); (node as CustomNodeViewModel).StrokeThickess = 1; (node as CustomNodeViewModel).StrokeDash = double.MaxValue; } } }