We're using silverlight in a kiosk type scenario. Is there a way to disable the right click ability to enter the silverlight configuration dialog?
//in the SharePoint I have added a Small code to tell SP to run the script after every part is loaded. Works like a charm :)
// EDIT
or better yet the silverlight forum recommends you do this: Silverlight Forum
<div id="silverlightObjDiv">
<!-- silverlight object here -->
</div>
<script>
_spBodyOnLoadFunctionNames.push ('setupElement');
function setupElement ()
{
document.getElementById('silverlightObjDiv').oncontextmenu = disableRightClick;
}
function disableRightClick(e) {
if (!e) e = window.event;
if (e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false;
}
}
</script>
As Dain mentioned, in Silverlight 4 you can do this easily:
Make the control windowless:
<param name="windowless" value="true" />
Trap the right click in your root grid/layout control:
public MainPage()
{
LayoutRoot.MouseRightButtonDown += (s, e) => { e.Handled = true; };
}
The catch
In Firefox and Chrome you have to choose between having a context menu or having mousewheel scroll capabilities. Sadly you can't have both, hopefully this will change in Silverlight 5.
In Silverlight 4 you can do it in C#, without fiddling with and being dependent on any HTML.
The example below shows how to implement right click to be actually used by a control, but you can just create a clicktrap if you only want to disable.
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
// wire up the event handlers for the event on a particular UIElement
ChangingRectangle.MouseRightButtonDown += new MouseButtonEventHandler(RectangleContextDown);
ChangingRectangle.MouseRightButtonUp += new MouseButtonEventHandler(RectangleContextUp);
}
void RectangleContextUp(object sender, MouseButtonEventArgs e)
{
// create custom context menu control and show it.
ColorChangeContextMenu contextMenu = new ColorChangeContextMenu(ChangingRectangle);
contextMenu.Show(e.GetPosition(LayoutRoot));
}
void RectangleContextDown(object sender, MouseButtonEventArgs e)
{
// handle the event so the default context menu is hidden
e.Handled = true;
}
}
Reference: http://timheuer.com/blog/archive/2009/11/18/whats-new-in-silverlight-4-complete-guide-new-features.aspx#rightclick
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With