This is a mirror of official site: http://jasper-net.blogspot.com/

How to Disable right click popup menu in a MVVM silverlight 4.0 application

| Thursday, February 10, 2011
The business problem

The silverlight configuration dialog has got a lot of useful functionality and the ability to quickly uninstall the application However most of the time you would want to prevent the business users from knowing the details of implementation.There is also a possibility that the business users could change a few settings inadvertently and cause the application from working or worse they could uninstall the application without knowing to install the application back again.

The image belows shows a test solution which shows the right click menu which appears by default.

Solution

One possible approach for solving this problem would be to use javascript to disable the right click at the plugin level.This approach however would disable the right click event for the entire application and will not work in out of browser mode. The solution presented in this article uses the right click event handler exposed in the silverlight 4 version and will not work in the previous versions of the silverlight. The solution is to add an event handler to the mouse right button down event in the application startup method.In the event handler we set the ishandled property to true.This essentially prevents the event from bubbling up all the way to the silverlight plugin.The source code for the same is shown below.

private void Application_Startup(object sender, StartupEventArgs e)
{          
     Application.Current.RootVisual.MouseRightButtonDown += new System.Windows.Input.MouseButtonEventHandler(RootVisual_MouseRightButtonDown);
}

void RootVisual_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    e.Handled = true;
}

private void Application_Exit(object sender, EventArgs e)
{
   Application.Current.RootVisual.MouseRightButtonDown -= new System.Windows.Input.MouseButtonEventHandler(RootVisual_MouseRightButtonDown);
}

It appears to be a easy work around ,However we still have a problem.It can be observed that when the datepicker popup window is open the user could right click in to the popup control and get the configuration dialog.

Read more: Codeproject

Posted via email from Jasper-net

0 comments: