Questions on Diagram Context Menu

I have been working with the Diagram Context menu and have two questions:

  1. When doing a Copy and Paste activities, I'd like to provide custom logic to ensure the entire contents of the node are copied/pasted and not just the node itself. I have added the MenuItemClickedEvent hendler as described in the documentation but when I click on Copy while running the program, the event is never called. The code I have is:
  2. (Info as IGraphInfo).MenuItemClickedEvent += OnMenuItemClicked;

  3. I am working to localize the application to Spanish and have Resources files with all of my strings in English (SystemStrings.resx) and Spanish (SystemStrings.es.resx). I have also included the ContextMenu strings as described in the documentation:


    Additionally, I have added the reference to the resources in the load of the diagram

    However, when I run the application, the values for the standard menu items are not properly localized.

Your assistance with these items is appreciated.


8 Replies

DT Deepa Thiruppathy Syncfusion Team May 23, 2022 10:59 AM UTC

Hi Stephen,


Please find below response table for all your queries,


Queries

Response

1.When doing a Copy and Paste activities, I'd like to provide custom logic to ensure the entire contents of the node are copied/pasted and not just the node itself. I have added the MenuItemClickedEvent hendler as described in the documentation but when I click on Copy while running the program, the event is never called. The code I have is:

(Info as IGraphInfo).MenuItemClickedEvent += OnMenuItemClicked;

 

This issue has been fixed in our latest. We request you use Latest version of SfDiagram control to avoid this issue.

2.I am working to localize the application to Spanish and have Resources files with all of my strings in English (SystemStrings.resx) and Spanish (SystemStrings.es.resx). I have also included the ContextMenu strings as described in the documentation:

We request you refer below sample for localizing the context menu items.

 

Sample link: https://github.com/SyncfusionExamples/WPF-Diagram-Examples/tree/master/Samples/Localization


Regards,

Deepa Thiruppathy



SS Stephen Shake May 24, 2022 11:45 PM UTC

Thank you for the reply. I downloaded the latest version and the MenuItemClickedEvent does now fire properly. I do however have a couple follow up questions. 

  1. If I do use the MenuItemClickedEvent for custom handling the Paste command, how do I get access to the object that was copied to properly deal with it in code? In looking at the Item and Source properties of the args parameter, I don't see a way to know what is being pasted back to the diagram.
  2. I followed the example for localization of the context menu but I still do not have the localization working. II have added the sample project for reference. I don't see where I am off on  the implementation.
  3. Is it possible to have the Diagram menu with customized menu options but NOT the default options of Copy, Cut, Paste and Select All; or with just Select All and not the others? As I could have a solution without Copy and Paste, if these could be hidden while still having other options, that would work well.

 


Attachment: ColorPalletteSample_e0699b5e.zip


DT Deepa Thiruppathy Syncfusion Team May 25, 2022 01:29 PM UTC

Please find below response table for all your queries,


Query

Response

If I do use the MenuItemClickedEvent for custom handling the Paste command, how do I get access to the object that was copied to properly deal with it in code? In looking at the Item and Source properties of the args parameter, I don't see a way to know what is being pasted back to the diagram.

 

To achieve this requirement, we request you use ItemAddedEvent instead of MenuItemClickedEvent. You can get the paste command information from PasteCommandInfo property of ItemAddedEventargs at ItemAddedEvent.

 

Code snippet:

private void MainWindow_ItemAdded(object sender, ItemAddedEventArgs args)

{

    if (args.Info != null)

    {

        //Getting paste command information.

        var pasteCommandInfo = args.Info as PasteCommandInfo;

    }

}

 

Note: PasteCommandInfo will be generated only if you set ID for nodes and other elements

 

I followed the example for localization of the context menu but I still do not have the localization working. II have added the sample project for reference. I don't see where I am off on  the implementation.

 

We are validating the given sample project. We will update the more details on May 27, 2022.

Is it possible to have the Diagram menu with customized menu options but NOT the default options of Copy, Cut, Paste and Select All; or with just Select All and not the others? As I could have a solution without Copy and Paste, if these could be hidden while still having other options, that would work well.

 

You can add additional menu items with default context menu items of Diagram. Please find below UG documentation link to know more about content menu and its customization,

 

https://help.syncfusion.com/wpf/diagram/context-menu



DT Deepa Thiruppathy Syncfusion Team May 26, 2022 09:15 AM UTC

Hi Stephen,


Reported issue: Localization for ContextMenu items is not working


We have validated the reported issue in your application. You are not used the resources file names properly. You have created the resource file as “SystemStrings” name in your application. To localize the SfDiagram control strings, resource files should be created in the name of SfDiagram control assembly name. For example: Syncfusion.SfDiagram.WPF.es.rex



Also, the same name should be used to initialize the ResourceManger.


Code snippet:


//Set up diagram localization

Assembly assembly = this.GetType().Assembly;

ResourceManager manager = new ResourceManager("ColorPalletteSample.Resources.Syncfusion.SfDiagram.WPF", assembly);


Please find below UG link to know more about localization resource file names,


https://help.syncfusion.com/wpf/localization#creating-resx-files



Modified sample link:
https://www.syncfusion.com/downloads/support/directtrac/general/ze/ColorPalletteSampleLocalization-1278635782


Regards,

Deepa Thiruppathy



SS Stephen Shake July 9, 2022 10:34 PM UTC

I am coming back around to this issue after working on some other items. I have validated that if I create a standard C# XAML application and use the correctly named assembly for the ResourceManager, I do have the context menu properly localized. However, the solution I have created is a Visual Studio Extension. I have made various attempts to properly access the correct path to the extension assembly but the context menu does not localize properly. All the other strings do localize (as seen above. But not the built-in menu.

In order to help troubleshoot this, I have created a sample VS extension (this is currently for 2019). I am including both the VSIX (inside the .zip file to allow it to be uploaded) and the source code for debugging. This has been localized for Spanish so be sure Visual Studio is set for Spanish.

To get to the diagram widow, open the IDE without code and then select Ver/Otras ventanas/Test of Diagram Tool Window. When the window appears, right-click the diagram. You will see that the built-in menus do not localize but my custom one does.


I have added code to catch the Context Menu opening event and place simple code to test reading the menu name from the resource manager. Surprisingly, this is localized.


Any thought here would be appreciated.


Attachment: SampleToolWindow_33f34c06.zip



DT Deepa Thiruppathy Syncfusion Team July 12, 2022 08:43 AM UTC

Hi Stephen Shake,


We are checking on your requirement. We will get back to you with more details on July 13, 2022.



DT Deepa Thiruppathy Syncfusion Team July 15, 2022 04:26 AM UTC

Hi Stephen,


Sorry for the inconvenience caused. We are still working on your requirement. We will update more details on July 18, 2022.



PP Prakash Perumal Syncfusion Team July 18, 2022 05:46 PM UTC

Hi Stephen,


As application use an external program for Start action, we couldn’t be able to apply culture to it. So, we suggest you to use the below work around solution to resolve this issue. 


private void OnMenuOpening(object sender, MenuOpeningEventArgs args)

{

       foreach (var menuitem in testDiagram.Menu.MenuItems)

       {

             if (menuitem.Content != null)

             {

                    var content = menuitem.Content.ToString();

                    if (content == "Cut") menuitem.Content = _manager.GetString("ContextMenu_Cut");

                    else if (content == "Copy") menuitem.Content = _manager.GetString("ContextMenu_Copy");

                    else if (content == "Paste") menuitem.Content = _manager.GetString("ContextMenu_Paste");

                    else if (content == "Select All") menuitem.Content = _manager.GetString("ContextMenu_SelectAll");

             }

       }

}


Regards,

Prakash


Loader.
Up arrow icon