Bugfix connection deletion

Unfortunatly the original version of the diagram designer from codeproject contains a bug. If you select a connection as on the following screenshot and hit the delete-key, the connection will not be deleted.

WPF Diagram Designer - Delete Connection

Fortunatly it’s quite easy to fix this bug.

  1. Open the file Connection.cs
  2. Change the line 25 according to the code below (e.Handled = false to e.Handled = true)
        protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);

            // usual selection business
            DesignerCanvas designer = VisualTreeHelper.GetParent(this) as DesignerCanvas;
            if (designer != null)
            {
                if ((Keyboard.Modifiers & (ModifierKeys.Shift | ModifierKeys.Control)) != ModifierKeys.None)
                    if (this.IsSelected)
                    {
                        designer.SelectionService.RemoveFromSelection(this);
                    }
                    else
                    {
                        designer.SelectionService.AddToSelection(this);
                    }
                else if (!this.IsSelected)
                {
                    designer.SelectionService.SelectItem(this);
                }

                Focus();
            }
            e.Handled = true; // In the original file this line is: e.Handled = false;
        }

If you now hit the delete key, the connection will be deleted correctly!


One thought on “Bugfix connection deletion

Comments are closed.