我正在创建我的自定义超链接按钮,该按钮是从Silverlight Hyperlinkbutton派生的,我想创建右键单击和中间单击事件。可以帮我。
谢谢gobind
我会添加几个事件(例如MiddleClick
和RightClick
),然后处理MouseUp
(或MouseDown
,如果您想在向下拦截),然后触发两个事件之一取决于MouseUp事件的详细信息。例如:
public MyControl()
{
InitializeComponent();
MouseUp += OnMouseUp;
}
void OnMouseUp(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Middle)
{
OnMiddleClick(e);
e.Handled = true;
return;
}
if (e.ChangedButton == MouseButton.Right)
{
OnRightClick(e);
e.Handled = true;
return;
}
}
public event MouseButtonEventHandler RightClick;
protected virtual void OnRightClick(MouseButtonEventArgs e)
{
var handler = RightClick;
if (handler != null) handler(this, e);
}
public event MouseButtonEventHandler MiddleClick;
protected virtual void OnMiddleClick(MouseButtonEventArgs e)
{
var handler = MiddleClick;
if (handler != null) handler(this, e);
}