参考解决办法:http://www.cnblogs.com/tianguook/archive/2011/05/13/2045299.html

在构造函数中首先添加一个事件:

 public BtnLists()
{
InitializeComponent();
btnCredit.AddHandler(BtnLists.MouseLeftButtonDownEvent, new MouseButtonEventHandler(this.btnCredit_MouseLeftButtonDown), true);
}

然后此事件就可以触发了:

 #region  账户管理按钮的单击事件
private void btnCredit_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
OnCreditClick(this,e);
}
public delegate void CreditClickHandler(object sender, RoutedEventArgs e); public event CreditClickHandler CreditClick; private void OnCreditClick(object sender, RoutedEventArgs e)//事件的注册
{
if (CreditClick != null)
{
CreditClick(this, e);
}
}
#endregion

翻译一下,从这个网站看到Button 的这两个事件无法触发的解决办法  http://www.silverlightshow.net/items/Tip-How-to-handle-the-MouseLeftButtonDown-and-MouseLeftButtonUp-events-of-the-Button-control.aspx

原文:

 
Have you ever noticed that the MouseLeftButtonDown and MouseLeftButtonUp events are not fired when a Silverlight button is clicked? The reason for this is that the button handles these two events itself by overriding the OnMouseLeftButtonDown  and the OnMouseLeftButtonUp  handlers. In the OnMouseLeftButtonDown  override, the Click event is raised and the MouseLeftButtonDown event is marked as handled so it couldn't bubble in the visual tree. The OnMouseLeftButtonUp  override also marks the MouseLeftButtonUp  as handled.

This thing can be changed using the ClickMode property of the Button control. It has the following values - Hover, Press, Release. The default one is Pressed and we have already explained it. When we have ClickMode set to Release, the Click event will be raised in the OnMouseLeftButtonUp override and the MouseLeftButtonDown and MouseLeftButtonUp events will be handled inside the button again. If we set the ClickMode to Hover, the Click event will be raised with the MouseEnter event and we will also be able to use the mouse button events.

That's it!

译:

你曾经是否注意到当一个Siverlight 按钮被单击时,MouseLeftButtonDown和MouseLeftButtonUp这两个事件并没有被触发?这个现象的原因是这个按钮通过重写OnMouseLeftButtonDown和OnMouseLeftButtonUp 自发地处理了这两个事件。在OnMouseLeftButtonDown重写中,单击事件被触发、MouseLeftButtonDown事件被标志为已处理,所以它没有被触发(翻译有出入,这个不知道怎么翻译。。so it couldn't bubble in the visual tree)。在OnMouseLeftButtonUp重写方法中同样也将MouseLeftButtonUp 设置为已处理。

可以通过改变Button 按钮的ClickMode属性来改变这个事实。它有以下属性值:Hover,Press,Release. 默认的是Pressed,这个我们已经解释了。当我们将ClickMode的属性设置为Release时,Click事件在OnMouseLeftButtonUp重写方法中会被触发,MouseLeftButtonDown和MouseLeftButtonUp事件在这个按钮里面又会被处理。如果我们将ClickMode的属性设置为Hover,这个单击事件会在MouseEnter事件中触发,这样我们也就可以用鼠标按钮的事件了。

silverlight MouseLeftButtonDown事件总是无法触发的更多相关文章

  1. silverlight 双击事件

    silverlight的一些功能真让我感到惊奇 就拿双击事件来说一下 写一个简单的例子 <StackPanel x:Name="st_De" MouseLeftButtonD ...

  2. DataGridView的Cell事件的先后触发顺序

    最近正在使用“DataGridView”对一个旧的Vs 2003开发的WINDOWS应用程序进行改造. 发现Vs 2003中的"DataGrid"中的一些事件已经在新的控件Data ...

  3. C# 之 FileSystemWatcher事件多次触发的解决方法

    1.问题描述  程序里需要监视某个目录下的文件变化情况: 一旦目录中出现新文件或者旧的文件被覆盖,程序需要读取文件内容并进行处理.于是使用了下面的代码: public void Initial() { ...

  4. jQuery 学习笔记(5)(事件绑定与解绑、事件冒泡与事件默认行为、事件的自动触发、自定义事件、事件命名空间、事件委托、移入移出事件)

    1.事件绑定: .eventName(fn) //编码效率略高,但部分事件jQuery没有实现 .on(eventName, fn) //编码效率略低,所有事件均可以添加 注意点:可以同时添加多个相同 ...

  5. JQuery如何实现双击事件时不触发单击事件

    单击和双击事件的执行顺序: 单击(click):mousedown,mouseout,click: 双击(dblclick):mousedown,mouseout,click , mousedown, ...

  6. JavaScript点击事件-一个按钮触发另一个按钮

    <input type="button" value="Click" id="C" onclick="Go();" ...

  7. 错误:“ResourceDictionary”根元素需要 x:Class 特性来支持 XAML 文件中的事件处理程序。请移除 MouseLeftButtonDown 事件的事件处理程序.

    原文:错误:"ResourceDictionary"根元素需要 x:Class 特性来支持 XAML 文件中的事件处理程序.请移除 MouseLeftButtonDown 事件的事 ...

  8. PB事件/函数的触发机制和触发方式

    PB作为windows下的一个非常便捷的DB开发工具,有着和windows一样的消息触发机制PB提供了相应event/function触发机制和触发方式,用户可以根据自己的实际需要选用不同方法. 1. ...

  9. jQuery的事件绑定与触发 - 学习笔记

    jQuery的事件绑定与触发 事件绑定 自动触发事件 常用的鼠标事件 事件冒泡和默认行为 事件冒泡 默认行为 获得当前鼠标的位置和按键 jQuery的事件绑定与触发 事件绑定 基本绑定 $(eleme ...

随机推荐

  1. Changing the Color of Linux ls Command 改变Linux的ls命令显示的颜色

    Linux command ls basically use the file /etc/DIR_COLORS or /etc/DIR_COLORS.xterm to define the color ...

  2. TCL:读取表格(xls)中的数据

    intToChar.tcl # input a number : 1 to 32 , you will get a char A to Z #A-Z:1-32 proc intToChar {int} ...

  3. 用cookie记住用户名

    有时候,我们在做登陆框时会有个复选框选择请记住我,或者有时候会遇到一些弹出框说下次不再提醒,此功能我们可以用js中的cookie实现此功能 下面记录一下如何实现该功能: 利用cookie记录用户名 1 ...

  4. php 正则

    1.中括号 [0-9]匹配0-9 [a-z]匹配a-z小写字母 [A-Z]匹配A-Z大写字母 [a-zA-Z]匹配所有大小写字母 可以使用ascii来制定更多 2.量词 p+匹配至少一个含p的字符串 ...

  5. Linux初记

    ctrl+u可以在shell下删除行,如果此键不起作用,就试试ctrl+x ctrl+z可以将程序挂起,不会终止程序,但可以将程序挂起. 通过fg命令可再把此作业切换到前台 cp命令的目标文件如果是一 ...

  6. JS继承模式粗探

    之前提到了JS中比较简单的设计模式,在各种设计模式中被最常使用的工具之一就是原型链的继承.作为OOP的特质之一——继承,今天主要谈谈JS中比较简单的继承方法. 最基础的原型链继承在这里就不复述了,主要 ...

  7. 【C-01关键字】

    一.语句引导关键字 for   while   swith  if  do   goto   return 二.限定关键字 const  static   extern 三.预编译关键字 #inclu ...

  8. CMD命令小结

    C:\Windows\Explorer.exe “文件具体目录(要加文件后缀名)”,(Explorer.exe后有一个空格,例如C:\Windows\Explorer.exe C:\temp\New ...

  9. SWT:获取字符串实际宽度

    由于SWT取用的是系统文字size,有个简单方式可以获取一整段包含中文\英文\数字\特殊字符的字符串宽度. 即是利用Label的computeSize方法,我们知道Label的大小可以随着内容文字伸缩 ...

  10. ENode 1.0 - 框架的物理部署思路

    开源地址:https://github.com/tangxuehua/enode 上一篇文章,介绍了enode框架的总体目标,以及如何实现高吞吐.低延迟.高可用.无单点问题的实现思路.本篇文章,我们再 ...