text: You may have noticed that right clicking on a Silverlight application brings up the following context menu and configuration dialog:
  Context Menu:
  Configuration Dialog:
  So what if you want to use right click in your application? While right click functionality is not currently supported in Silverlight, there is a work-around. I will step you through how to intercept the right click event, process it and display your own content instead of the Silverlight dialog.
  Step 1. To start, let’s add a <TextBlock> control to our Page.xaml to track the status of the right click:
  <UserControl x:Class="SilverlightApplication15.Page"
  xmlns=""
  xmlns:
  <Grid x:
  <TextBlock x:Right click please.</TextBlock>
  </Grid>
  </UserControl>
  Step 2. Next, we need to set the Silverlight control to be windowless. Open the web page (i.e. default.aspx) that contains the Silverlight control and add the tag Windowless=”true” to it. Example:
  <asp:Silverlight
  Step 3: Finally, let’s take a look at the code we add to Page.xaml.cs.
  Page.xaml.cs:
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Net;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Animation;
  using System.Windows.Shapes;
  using System.Windows.Browser;
  namespace SilverlightApplication15
  {
  public partial class Page : UserControl
  {
  ContextMenuInterceptor _cmi = null;
  public Page()
  {
  InitializeComponent();
  _cmi = new ContextMenuInterceptor(MyField);
  }
  }
  public class ContextMenuInterceptor
  TextBlock TextField;
  public ContextMenuInterceptor(TextBlock textField)
  TextField = textField;
  HtmlPage.Document.AttachEvent("oncontextmenu", this.OnContextMenu);
  private void OnContextMenu(object sender, HtmlEventArgs e)
  TextField.Text = "Right Clicked Blocked at "+e.OffsetX+","+e.OffsetY;
  e.PreventDefault();
  }
  }
  Thank you,
  --Mike Snow
  Subscribe in a reader
  Interested in learning something new about Silverlight almost every day? I will be posting “Tips of the
  You may have noticed that right clicking on a Silverlight application brings up the following context
  you may want to go here and snag this guy's code he was way ahead of you and it works better. even lets you choose to display a HTML or XAML menu. but he never updated for beta 2
  his would work even if the page was scrolled or the SL control was deeply nested. you could probably even use that HTMLPage object to do what he did in javascript to say where in the SL control the click occured instead of where on the page.
  marty
  Marty- Thanks for the link. Looks like his method is to handle the right click from JScript. I am not sure how it is better (lot more code involved) but it's definitely a good alternative approach.
  Btw, there is a lot more you can do to my code. It's only meant to be a starting place to get people going.
  yup it is in the javascript. if you want an HTML menu you handle it there if you want a XAML menu you call the managed code function from javascript with the coordinates it gives you that tells you the x and y of the click according to the SL control and not the page.
  you guys should put your solutions together. that would make the right click as easy to use as the other mouse events. it would be even better if microsoft just let us do what we wanted with the right click.
  在flash中 其提供了一个可定制话的右键菜单系统.(ContextMenu)
  16 posts today... yikes: Corrina Barber on Sparkling Client, Training CD update via Tim Heuer, Progressive
  Why don't we get the configuration dialog when we right click a Silverlight app in Firefox?
  Pingback from Silverlight news for July 2, 2008
  Pingback from 14 Silverlight Tips | DavideZordan.net
  Since the Mac only has one mouse button, what happens there? Is it Ctrl+Click or something?
  Alan- This article talks about how to right click on the mac:
  Jag tänkte jag skulle börja samla ihop bra länkar och resurser som jag hittar och publicera dessa veckovis
  Great post! Here's an extended version I put together that adds behavior similar to MouseEventArgs.
  namespace SteveCommisso.Silverlight.Utils
  public class ContextMenuExtender
  {
  public UIElement ExtendedElement { get; private set; }
  public ContextMenuExtender(UIElement extendedElement) {
  this.ExtendedElement = extendedElement;
  HtmlPage.Document.AttachEvent("oncontextmenu", this.OnContextMenu);
  }
  public event RightClickHandler RightClick;
  private void OnContextMenu(object sender, HtmlEventArgs e) {
  if (RightClick != null) {
  if (ExtendedElement.IsHitTestVisible) {
  Point clickPoint = new Point(e.OffsetX, e.OffsetY);
  List<UIElement> hitElements = new List<UIElement>(ExtendedElement.HitTest(clickPoint));
  if (hitElements.Count > 0) {
  e.PreventDefault();
  e.StopPropagation();
  RightClick(this, new RightClickEventArgs(ExtendedElement, clickPoint));
  }
  }
  }
  }
  public delegate void RightClickHandler(object sender, RightClickEventArgs e);
  public class RightClickEventArgs
  public UIElement Source { get; private set; }
  public Point RelativePoint { get; private set; }
  public Point AbsolutePoint { get; private set; }
  internal RightClickEventArgs(UIElement source, Point absolutePoint) {
  this.Source = source;
  this.AbsolutePoint = absolutePoint;
  this.RelativePoint = GetPosition(Source);
  public Point GetPosition(UIElement relativeTo) {
  GeneralTransform transform = Application.Current.RootVisual.TransformToVisual(relativeTo);
  return transform.Transform(AbsolutePoint);
  Oops -- posted too early. RightClickEventArgs should inherit from EventArgs:
  public class RightClickEventArgs : EventArgs
  Thanks for posting this... I had a really hacky javascript implementation I was working with. The key in this one was attaching the oncontextmenu event handler at the document level, rather than at an element level (for example, a DIV containing the Silverlight control). This allows it to work in FireFox/Safari as well as IE.
  Hi,
  I'm just beginning with Silverlight...
  Thanks a lot for this tip, it's very helpfull !
  But there is something that I don't understand, it does work on IE7 but not on Firefox, I don't know how to fix it !
  Scommisso said "The key in this one was attaching the oncontextmenu event handler at the document level, rather than at an element level (for example, a DIV containing the Silverlight control). This allows it to work in FireFox/Safari as well as IE." i don't know how to do it ?
  Thanks in advance.
  That's really Cool.
  Thanks.
  The technique described doesn't seem to work in SL 2.0 B2.
  Even though HtmlPage.Document.AttachEvent is being executed in the constructor of my Page UserControl, when I RightMouse click the OnContextMenu routine is not being called and the Silverlight Configuration popup stil appears. Why is that?
  Also this design doesn't quite fill my need. I may have more than one UserControl that requires action on RightMouseButtonDown. I need to be able to add EventHandlers for each of the controls and not just the Browser page.
  Any ideas on how to make this work?
  Dbaechtel - What browser are you using?
  Also, if you want to do it per user control just get the coordinates of where the right click occured then determine which control that click hit based upon its location on the screen. Just an idea.
  Also, make sure to set windowless=true
  If you set windowless=true, the Safari does not show the SL.
  How can we solve this problem
  同flash一样，silverlight默认的右键菜单显示的内容也是关于这个插件的信息，要自定义silverlight右键菜单，其实也是很简单的。
  首先需要自定义右键菜单的内容（当然你也可以根据需要...!!! Before I read this post, I tried the javascript solution with something like "silverlightControl.Content.ActualSilverlightControl.ProcessMouseEvent(e);" which is an ugly hack and doesn't seem to work with Silverlight 3.
  But this solution works really great! You are my hero :-)
  Also thanks to scommisso. I began to write the same class he did :-)
  Pingback from 7 tips for extending browser functionality to Silverlight apps | Igor Ostrovsky Blogging
  I can't make this sample work :(