locked
Create context menu Blend 4 RC RRS feed

  • Question

  • I see in the silverlight toolkit (April 2010) where the context menu has been added, but can this be accessed directly in blend?

     

    If not, is there a relevant link to creating a context menu in Silverlight and Sketchflow?

    Wednesday, May 19, 2010 4:43 PM

Answers

  • Its a popup control. Type in popup into the blend search under the assets button on the left hand toolbar.

     

    Here is a sample implementation:

    private Popup CreateContextMenu(Point currentMousePosition)
    {
      Popup popup = new Popup();
      Grid popupGrid = new Grid();
      Canvas popupCanvas = new Canvas();
    
      popup.Child = popupGrid;
      popupCanvas.MouseLeftButtonDown += (sender, e) => { HidePopup(); };
      popupCanvas.MouseRightButtonDown += (sender, e) => { e.Handled = true; HidePopup(); };
      popupCanvas.Background = new SolidColorBrush(Colors.Transparent);
      popupGrid.Children.Add(popupCanvas);
      popupGrid.Children.Add(CreateContextMenuItems(currentMousePosition));
    
      popupGrid.Width = Application.Current.Host.Content.ActualWidth;
      popupGrid.Height = Application.Current.Host.Content.ActualHeight;
      popupCanvas.Width = popupGrid.Width;
      popupCanvas.Height = popupGrid.Height;
    
      return popup;
    }
    void brdRightClickZone_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
    {
      txbMessage.Text = "Right Clicked";
      Point currentMousePosition = e.GetPosition(LayoutRoot);
      ShowPopup(currentMousePosition);
    }
    
    private void btnRightClick_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
    {
      e.Handled = true;
    }

    Reference:
    http://www.codeproject.com/KB/silverlight/SL4RightClickContextMenu.aspx

    • Marked as answer by ericwyman Friday, May 21, 2010 2:02 PM
    Wednesday, May 19, 2010 6:45 PM