参考解决办法: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. Postman-进阶

    Postman-简单使用 Postman-进阶使用 Postman-CI集成Jenkins 管理请求 保存请求-添加“打开百度首页请求” 设置请求方式为Get,地址为www.baidu.com.点击右 ...

  2. javascript练习-扑克牌

    下面用枚举类型来实现一副扑克牌的类: //定义一个玩牌的类 function Card(suit,rank){ function inherit(p){ if(p==null) throw TypeE ...

  3. 如何参与Linux内核开发(转)

    本文来源于linux内核代码的Document文件夹下的Hoto文件.Chinese translated version of Documentation/HOWTO If you have any ...

  4. 深入剖析Nginx一点小笔记

    前几天在图书馆看书,恰好看到这本<深入剖析nginx>,花了快一周的时间看完了这本书,写点笔记心得便于以后复习. 以前对nginx的认识就只是停留在一个反向代理服务器上.百度了一下ngin ...

  5. JavaScript 基础第十天

    学习总结 1定时器 ①.setTimeout() // 间隔多长时间执行一次(会返回一个数字型的标识) ②.setInterval() // 间隔多长时间执行,是不断地执行. ③.clearTimeo ...

  6. 关于css3媒体查询和响应式布局

    响应式设计 响应式设计可根据所显示的屏幕大小而改变, 它呈现的每个屏幕看起来并不相同.按照可用的屏幕属性,响应式设计提供了 UI 的最佳效果. 例如,如果网站布局上有一个占据 25% 的屏幕宽度的侧边 ...

  7. mvc2/3/4_伪静态_路由配置

    一.路由规则: routes.MapRoute(                name: "Default2",                url: "{contr ...

  8. Ubuntu之root权限的获取

    方案一: Ubuntu的root密码在没有设置之前是随机的,即在每一次开机的时候他的密码都不同,但是由于在安装Ubuntu的时候需要建立一个账户,而这个招呼又属于admin组,因此它可以对root进行 ...

  9. 彻底理解ThreadLocal一

    synchronized这类线程同步的机制可以解决多线程并发问题,在这种解决方案下,多个线程访问到的,都是同一份变量的内容.为了防止在多线程访问的过程中,可能会出现的并发错误.不得不对多个线程的访问进 ...

  10. Oracle EBS进化史

    https://blogs.oracle.com/ptian/entry/oracle_ebs%E8%BF%9B%E5%8C%96%E5%8F%B2 通过图表总结了下Oracle EBS的进化历史,回 ...