.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Articles >> Silverlight >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Disable Right Click in Silverlight Application

Posted By:Diptimaya Patra       Posted Date: March 25, 2010    Points: 25    Category: Silverlight    URL: http://www.dotnetspark.com  

Disable Right Click in Silverlight Application. In this article we will see how can we disable the ContextMenu when you Right Click on Silverlight Page .


In this article we will see how can we disable the ContextMenu when you Right Click on Silverlight Page .

Crating Silverlight Project

Fire up Visual Studio 2008 and create a Silverlight Application. Name it as DisableContextMenuSL3.


Default Context Menu

In any Silverlight Application when you right click on it you see a context menu containing Item "Silverlight". Like following:


And when you click on it you find the Silverlight Configuration Dialog popping up.


Disabling Context Menu

What if we don't want the Context Menu and don't want to see the Configuration dialog. We will see how we can do that.

  1.  First of all open the "DisableContextMenuSL3TestPage.aspx" page and find the object tag where Silverlight Plug in is being hosted.


  2. Now add a param tag with name="Windowless" and value="true". By default its value is false.


  3. Now open "MainPage.xaml.cs". Add the Namespace "System.Windows.Browser"

    using System.Windows.Browser;

  4. Add a class inside the MainPage.cs name it as ContextMenuInterceptor.
  5. Add method OnContextMenu with arguments object and HtmlEventArgs.
  6. Add default constructor with the following code:

    HtmlPage.Document.AttachEvent("oncontextmenu", this.OnContextMenu);

    The full class definition looks like the following.

    public class ContextMenuInterceptor
      public ContextMenuInterceptor()
      HtmlPage.Document.AttachEvent("oncontextmenu", this.OnContextMenu);
      private void OnContextMenu(object sender, HtmlEventArgs e)

  7. Now in MainPage class create an instance of the Class you just created.

    ContextMenuInterceptor context = new ContextMenuInterceptor();

That's it Run your application and try to right click on the page. You won't get the Context Menu for Silverlight.

Enjoy Coding.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend