How to Cut a Group


#1

I can’t delete a Group.

After the user executes “Ungroup” from the context menu, the block is ungrouped, and the block and group appear separated, which is great. I can then right-click on the block and select “Cut” from the context menu and the block disappears, which again, is great. When I right-click on the group and select “Cut” from the context menu, the group does not disappear.

We’re using Northwoods routed commands to handle the “Cut”.

What is odd is that the “Copy” context menu does successfully make a copy of the Group, so I don’t know why the “Cut” context menu is not working straight out of the box.

I’m running GoWPF v2.2.3.45 on Windows 10, Visual Studio 2017.


#2

Odd, I just tried it in two of the samples in GoWpfDemo, and they both worked as I expected when I selected a Group and typed Ctrl-X, including executing repeated Ctrl-V afterwards.


#3

I hadn’t tried Ctl-X, just the Cut contextmenu. But unfortunately, Ctl-X doesn’t work on the Group either.

Ctl-C and Ctl-V (copy and paste) works fine.
Ctl-X and Ctl-V (cut and paste) works like the copy and paste above, the Group is not cut, only copied.

I can cut and paste other blocks, just not the Group block.

This is the Cut context menu:

            // Using Northwoods routed commands to handle a "Cut"
            var bmp = new BitmapImage(new Uri("Images/Cut_VS.png", UriKind.Relative));
            var img = new Image {Source = bmp};
            menuItem = new MenuItem {Header = "Cut", Command = Commands.Cut, Icon = img};
            items.Add(menuItem);

Is there a way to debug the Commands.Cut handler?


#4

Maybe you have disabled deleting the group?


#5

The whole time, I’ve been searching our code base for “cut” trying to find where the node is actually being removed so I could debug. Searching for “delete” led me to the right place.

Indeed, there is a switch statement right before the model.RemoveNode() call, and my new Group block was not one of the Case conditions. I have added:

            case "Group":
                model.RemoveNode(node.Data);
                break;

…and now I’m good to go.

Thanks for steering me in the right direction!