Skip to main content

Microsoft Silverlight

Answered Question Context Menu in Firefox RSS Feed

(0)

NemanjaM
NemanjaM

Member

Member

0 points

2 Posts

Context Menu in Firefox

 In IE context menu is working fine, but in FF it is working on every other click.

Has anyone found solution for it?

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP

Re: Context Menu in Firefox

 Can you share the code that you wrote for it? so we can try replicating this in our machine and see any solution

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


NemanjaM
NemanjaM

Member

Member

0 points

2 Posts

Re: Context Menu in Firefox

 In the constructor of the page I have added this segment of the code:

 public partial class GroupsAndAreasMainPage : Telvent.SilverlightExt.MVVM.View
{

        public GroupsAndAreasMainPage()
        {
        InitializeComponent();
        DataContext = GroupsAndAreasMainViewModel.GetInstance();
            InitView();

        HtmlPage.Document.AttachEvent("oncontextmenu", ((GroupsAndAreasMainViewModel)DataContext).OnContextMenu);
    }
}

  In ViewModel class I have a ContextMenu method like this:

 

public class GroupsAndAreasMainViewModel : ViewModel

    {
        public GroupsAndAreasMainViewModel()
        {
        }      
        
        public void OnContextMenu(object sender, HtmlEventArgs e)
        {
            
                Point clickPoint = new Point(e.OffsetX, e.OffsetY);
                List hittedElements = VisualTreeHelper.FindElementsInHostCoordinates(clickPoint, MainViewModel.GetInstance().LayoutRoot) as List;
                if (hittedElements.Count > 0)
                {
                    UIElement currentElement = null;

                    foreach (UIElement element in hittedElements)
                    {
                        currentElement = element;
                        if ((element.GetType().Name == "TreeViewItem" &&
                            ((((TreeViewItem)element).GetItem() is GATreeViewItem) || (((TreeViewItem)element).GetItem() is TreeViewItem)))
                            || (element.GetType().Name == "DataGridRow"))
                        {
                            break;
                        }
                    }

                    PopupItems.Clear();
                    GeneralTransform transform = Application.Current.RootVisual.TransformToVisual(LayoutRoot);
                    Point absolutePoint = new Point(e.OffsetX, e.OffsetY);
                    Point relativePoint = transform.Transform(absolutePoint);

                    if (currentElement != null)
                    {
                        if (currentElement.GetType().Name == "TreeViewItem")
                        {
                            PopupItems.Add(new PopupItem() { Name = "Add Area" });
                            PopupItems.Add(new PopupItem() { Name = "Edit Area" });
                            PopupItems.Add(new PopupItem() { Name = "Delete Area" });
                            
                            GAPagePopup.HorizontalOffset = relativePoint.X;
                            GAPagePopup.VerticalOffset = relativePoint.Y;
                            GAPagePopup.IsOpen = true;
                        }   
                    }
                }
            e.PreventDefault();
            e.StopPropagation();
        }
    }
}

  

I have deleted irrelevant parts of code.

 

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP

Re: Context Menu in Firefox

Please try with contextmenu in Firefox

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP
Answered Question

Re: Context Menu in Firefox

 You can also check this sample. http://www.sharpgis.net/post/2009/05/09/Adding-rightclick-to-Silverlight.aspx

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities