我正在创建源自Silverlight HyperlinkButton的自定义超链接按钮我想在其上创建右键单击和中键单击事件。请帮帮我吧。
谢谢, 戈宾德
答案 0 :(得分:0)
我会添加一些事件(例如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);
}