Context menu in sfTreeview for Xamarin.Forms like the one in the Treeview for WPF?

Hi,

I'm trying to implement a UWP application using Xamarin.Forms and the sfTreeview control. 
However, I was wondering: does it exist an equivalent of context menu for WPF treeviews (https://help.syncfusion.com/wpf/treeview/contextmenu) but for Xamarin.Forms? 

Thanks in advance,

Jorge

5 Replies 1 reply marked as answer

LN Lakshmi Natarajan Syncfusion Team February 21, 2021 11:05 AM UTC

Hi Jorge, 
 
Thank you for using Syncfusion products. 
 
We have checked the reported query “Context menu in sfTreeview for Xamarin.Forms like the one in the Treeview for WPF?” from our side. We would like to inform you that we have prepared a sample to show the context menu. You can show the menu by holding the node and right clicking on the UWP platform. 
 
Please refer to the sample in the following link, 
 
Please let us know if this helps. 
 
Lakshmi Natarajan 
  
 



JA Jorge Andrés February 22, 2021 12:13 PM UTC

Dear Lakshmi,

Thanks so much for the quick response and for the example! It works great. However, would it also be possible to handle close interactions, such as when the ESC key is pressed or when clicking another element besides the treeview?

Thanks in advance,
Jorge


LN Lakshmi Natarajan Syncfusion Team February 23, 2021 06:19 AM UTC

Hi Jorge, 
 
Thank you for the update. 
 
We have checked the reported query “would it also be possible to handle close interactions, such as when the ESC key is pressed or when clicking another element besides the treeview” from our side. We would like to inform you that you can achieve this scenario using custom renderer for the parent element of the TreeView. You can use the KeyDown event which will be triggered when key is pressed. Please refer to the following code snippets for more reference, 
  
[assembly: ExportRenderer(typeof(KeyDetector), typeof(KeyDetectorRenderer))] 
namespace TreeViewXamarin.UWP 
{ 
    public class KeyDetectorRenderer : VisualElementRenderer<KeyDetector, FrameworkElement> 
    { 
        private KeyEventArgs KeyEventArgs; 
 
        public KeyDetectorRenderer() 
        { 
            KeyEventArgs = new KeyEventArgs(); 
            this.KeyDown += KeyDetectorRenderer_KeyDown; 
            this.Tapped += KeyDetectorRenderer_Tapped; 
        } 
 
        private void KeyDetectorRenderer_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) 
        { 
            var grid = this.Element as KeyDetector; 
 
            if (grid != null) 
            { 
                KeyEventArgs.Key = "Dismiss"; 
                grid.RaiseKeyPressed(KeyEventArgs); 
            } 
        } 
 
        private void KeyDetectorRenderer_KeyDown(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e) 
        { 
            var grid = this.Element as KeyDetector; 
 
            if(grid != null) 
            { 
                KeyEventArgs.Key = e.Key.ToString(); 
                grid.RaiseKeyPressed(KeyEventArgs); 
            } 
        } 
    } 
} 
 
And you can dismiss the popup in the KeyPressed event. 
private void KeyDetectorGrid_KeyPressed(object sender, KeyEventArgs e) 
{ 
    if (e.Key == "Escape" || e.Key == "Dismiss") 
    { 
        popupLayout.Dismiss(); 
    } 
} 
 
We have updated our sample and you can download from the following link, 
 
Please let us know if you need further assistance. 
 
Lakshmi Natarajan 
 


Marked as answer

JA Jorge Andrés February 24, 2021 11:28 AM UTC

The example is quite enlightening. Thanks so much! 


LN Lakshmi Natarajan Syncfusion Team February 24, 2021 11:36 AM UTC

Hi Jorge, 
 
Thank you for the reply. 
 
We are glad that our solution meets your requirement. Please let us know if you need further assistance. As always we are happy to help you out. 
 
Lakshmi Natarajan 


Loader.
Up arrow icon