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?
+5
A:
// EDIT
or better yet the silverlight forum recommends you do this: Silverlight Forum
<div id="silverlightObjDiv">
<!-- silverlight object here -->
</div>
<script>
document.getElementById('silverlightObjDiv').oncontextmenu = disableRightClick;
function disableRightClick(e) {
if (!e) e = window.event;
if (e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false;
}
}
</script>
Eric Ness
2009-02-10 16:35:07
Genius! Thanks.
Jeremy
2009-02-10 18:34:22
A:
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;
}
}
dain
2010-08-10 10:30:12
+1
A:
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; };
}
Chris S
2010-08-10 10:37:13