SfTreeView add context menu.

Hi,

I would like to display a context menu for items in my SfTreeView. Is there a way to achieve this?

Thank you in advance for your assistance.

Best regards,
Youssef 


8 Replies

AF Anees Fathima Shajahan Syncfusion Team November 12, 2024 03:19 PM UTC

Hi Youssef Juma,


You can show the context menu by showing our SfPopup (with required menu items) through ItemLongPress event of SfTreeView. Please refer to the attached sample for more details and let us know if you have any other queries.

 

LongPress event UG: https://help.syncfusion.com/maui/treeview/working-with-treeview#itemlongpress-event

Popup UG : Getting Started with .NET MAUI Popup control | Syncfusion


Regards,

Anees Fathima.


Attachment: MauiTreeView_60a10ac0.zip


YJ Youssef Juma November 13, 2024 01:51 PM UTC

Hi Anees,

Thanks for your replay.

Could this also be done using ItemRightTapped? Currently, the popup is always positioned at the top, but I'd like to place it next to the right-tapped item. Is this possible?

Regards,

Youssef Juma



AF Anees Fathima Shajahan Syncfusion Team November 14, 2024 11:14 AM UTC

Hi Youssef Juma,


We can display the context menu using the ItemRightTapped event as well, but in this case, the e.Position.Y value is incorrect, causing the popup to appear at the top. This is a known issue on our end, and we are planning to address it in an upcoming NuGet release, which is scheduled for November 19, 2024. We appreciate your patience until then.

ItemRightTapped Event UG : https://help.syncfusion.com/maui/treeview/working-with-treeview#itemrighttapped-event

R
egards,

Anees Fathima.



YJ Youssef Juma November 14, 2024 12:53 PM UTC

Hi Anees Fathima,

Okay now I understand what is the issue , thanks for the update. 

Regards,
Youssef Juma 



JR Jayashree Ravishankar Syncfusion Team November 19, 2024 07:52 AM UTC

Hi Youssef Juma,

 

Sorry for the inconvenience,

 

The weekly release has been postponed to 20th November 2024, we will let you know once it is published. We appreciate your patience and understanding in the meantime.



AF Anees Fathima Shajahan Syncfusion Team November 22, 2024 05:13 AM UTC

Hi Youssef Juma,


We would like to let you know that Essential Studio Weekly NuGet packages (v27.2.3) has been published in nuget.org with the fix for the issue “TouchPosition is not obtained based on the screen position”.

We request you to use below sample workaround (i.e ignore the status bar height) also along the with this fix to show the popup on the touch position. Please refer to the attached sample and code snippet.

  

    private void treeView_ItemRightTapped(object sender, Syncfusion.Maui.TreeView.ItemRightTappedEventArgs e)

    {

        Node = e.Node;

#if WINDOWS

        statusBarHeight = _statusBarService.GetStatusBarHeight();

#endif

        var y = e.Position.Y - statusBarHeight;

        popup.Show(e.Position.X, y);

    }



RootCause of the issue:
The touch position is returned based on item bounds. Now touch position is calculated and returned based on-screen bounds.


Regards,

Anees Fathima.


Attachment: MauiTreeView_51931a3f.zip


YJ Youssef Juma November 22, 2024 11:36 AM UTC

Hi Anees Fathima,

The issue is now resolved thank you for the update.

Best Regards,

Youssef Juma 



JS Jayashree Suresh Anand Syncfusion Team November 25, 2024 06:52 AM UTC

Hi Youssef, 

We are glad that our proposed fix resolved the issue on your end, please let us know if you need any further assistance. Feel free to open a new forum for any new issue that may arise. 

Regards,

Jayashree 


Loader.
Up arrow icon