Telerik RadControls for Silverlight provide three routed events in addition to the Silverlight mouse events: MouseWheel, MouseDown and MouseUp. The latter two enable the developers to check for DoubleClick and RightClick in their applications. I will briefly show how to use this functionality:
1) MouseWheel:
using Telerik.Windows.Input; ... Mouse.AddMouseWheelHandler(element, OnMouseWheel); ... private void OnMouseWheel(object sender, MouseWheelEventArgs args) { var delta = args.Delta; }
In most cases you just need to make a ScrollViewer to respond on the mouse wheel rotations. We implemented this in the ScrollViewerExtensions.EnableMouseWheel attached behavior, so you don't have to:
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" <ScrollViewer telerik:ScrollViewerExtensions.EnableMouseWheel="true"> ... </ScrollViewer>
NOTE: To successfully handle the mouse wheel events, the Silverlight plugin should be in windowless mode.
2) RightClick
using Telerik.Windows.Input; ... Mouse.AddMouseUpHandler(element, OnMouseUp); ... private void OnMouseUp(object sender, MouseButtonEventArgs args) { var button = args.ChangedButton; if (button == MouseButton.Right) { // Hide the Silverlight context menu args.Handled = true; } }
NOTE: You can also use AddMouseDownHandler to handle the mouse down events. To successfully handle the mouse right click events, the Silverlight plugin should be in windowless mode.
RadContextMenu will be opened by default when the user clicks the right mouse button.
3) DoubleClick (support added in Q1 2009 SP1)
using Telerik.Windows.Input; ... Mouse.AddMouseUpHandler(element, OnMouseUp); ... private void OnMouseUp(object sender, MouseButtonEventArgs args) { var count = args.ClickCount; if (count > 1) { // Double click } }
Unfortunately due to some limitations of the Silverlight XAML parser we cannot provide support for attaching those events in the XAML. Still, the code-behind is completely WPF compatible.
In case you already have "using System.Windows.Input" you will get errors when compiling, saying MouseButtonEventArgs is an ambiguous reference. To resolve the problem you will have to either remove "using System.Windows.Input" from your code-behind, or reference MouseButtonEventArgs in the telerik handlers with its full name:
private void OnMouseUp(object sender, Telerik.Windows.Input.MouseButtonEventArgs args) { ... }
I hope this helps.