protected void OnAddBtnClicked(object sender, EventArgs e) { object model = Activator.CreateInstance(selectedModel); NodeDialog addDialog = new NodeDialog(model); if (addDialog.Run() == (int)ResponseType.Ok && !string.IsNullOrEmpty(model.ToString())) { //adding node to drawing area Type[] typeArgs = { selectedModel }; Type nodeType = typeof(Node <>); Type constructedNodeType = nodeType.MakeGenericType(typeArgs); object node = Activator.CreateInstance(constructedNodeType, model); NodeVisualization mvo = new NodeVisualization(node); mvpanel1.AddNode(mvo, 10, 10); } addDialog.Destroy(); }
private void EditNode_Click(object sender, RoutedEventArgs e) { var test = this; Label title = null; if (sender is MenuItem menuItem) { if (menuItem.CommandParameter is ContextMenu contextMenu) { title = contextMenu.PlacementTarget as Label; } } if (title == null) { return; } Node nodeToEdit = Find(title.Name); NodeDialog editNodeDialog = new NodeDialog(); editNodeDialog.TitleTextBox.Text = nodeToEdit.Title; editNodeDialog.Description.Document.Blocks.Clear(); editNodeDialog.Description.Document.Blocks.Add(new Paragraph(new Run(nodeToEdit.Description))); editNodeDialog.Red.Text = nodeToEdit.Color.R.ToString(); editNodeDialog.Green.Text = nodeToEdit.Color.G.ToString(); editNodeDialog.Blue.Text = nodeToEdit.Color.B.ToString(); editNodeDialog.ShowDialog(); if (editNodeDialog.DialogResult == true) { nodeToEdit.Title = !string.IsNullOrWhiteSpace(editNodeDialog.TitleTextBox.Text) ? editNodeDialog.TitleTextBox.Text : "node"; TextRange textRange = new TextRange(editNodeDialog.Description.Document.ContentStart, editNodeDialog.Description.Document.ContentEnd); string richText = textRange.Text; nodeToEdit.Description = !string.IsNullOrWhiteSpace(richText) ? richText : "node description"; var red = Convert.ToByte(!string.IsNullOrWhiteSpace(editNodeDialog.Red.Text) ? editNodeDialog.Red.Text : "0"); var green = Convert.ToByte(!string.IsNullOrWhiteSpace(editNodeDialog.Red.Text) ? editNodeDialog.Green.Text : "0"); var blue = Convert.ToByte(!string.IsNullOrWhiteSpace(editNodeDialog.Red.Text) ? editNodeDialog.Blue.Text : "0"); nodeToEdit.Color = Color.FromRgb(red, green, blue); } }
private void AddChildNode_Click(object sender, RoutedEventArgs e) { Label titleLabel = null; if (sender is MenuItem menuItem) { if (menuItem.CommandParameter is ContextMenu contextMenu) { titleLabel = contextMenu.PlacementTarget as Label; } } if (titleLabel == null) { return; } Node parent = Find(titleLabel.Name); NodeDialog addChildDialog = new NodeDialog(); addChildDialog.ShowDialog(); if (addChildDialog.DialogResult == true) { string title = !string.IsNullOrWhiteSpace(addChildDialog.TitleTextBox.Text) ? addChildDialog.TitleTextBox.Text : "node"; TextRange textRange = new TextRange(addChildDialog.Description.Document.ContentStart, addChildDialog.Description.Document.ContentEnd); string richText = textRange.Text; string description = !string.IsNullOrWhiteSpace(richText) ? richText : "node description"; var red = Convert.ToByte(!string.IsNullOrWhiteSpace(addChildDialog.Red.Text) ? addChildDialog.Red.Text : "0"); var green = Convert.ToByte(!string.IsNullOrWhiteSpace(addChildDialog.Red.Text) ? addChildDialog.Green.Text : "0"); var blue = Convert.ToByte(!string.IsNullOrWhiteSpace(addChildDialog.Red.Text) ? addChildDialog.Blue.Text : "0"); Color color = Color.FromRgb(red, green, blue); Node child = new Node(title, description, color, Menu); parent.AddChild(child); } }