参考解决办法: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. ListView之头部浮动效果

    ListView 中有时需要在顶部固定一个浮动栏,当向上滑动 ListView 时,浮动栏固定在顶部,当向下滑动 ListView 到其 HeaderView 可见时,浮动栏成为ListView的一部 ...

  2. <Oracle Database>逻辑结构

    逻辑结构 Oracle的逻辑结构是一种层次结构.主要由:表空间.段.区和数据块等概念组成.逻辑结构是面向用户的,用户使用Oracle开发应用程序使用的就是逻辑结构. 数据块 数据块是Oracle最小的 ...

  3. AOP 事务

    定义 AOP实际可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术,非业务类横切于业务类), 通过AOP以动态和非入侵方式来增强服务 事务的四大属性:ACID ...

  4. JMeter HTTP Cookie管理器的跨域使用

    Jmeter的一个测试计划只能有一个cookie管理器,当多个manager同时存在时,无法指定是用的哪一个manager.如果想让cookie manager跨域使用,修改JMeter.proper ...

  5. nginx Windows服务形式运行

    背景 现在使用ngnix的人越来越多,nginx的优势劣势网上也很多说明.这里就不探讨nginx优势与劣势,每个工具都有自己优势劣势,没有最好的工具,只有最合适的工具.   如何选择适当的工具,根据项 ...

  6. mavan 命令行创建项目

    1)创建简单maven项目 mvn archetype:create -DgroupId=cn.everlook.myweb -DartifactId=myweb -DpackageName=cn.e ...

  7. Python-变量

    1.Python的变量是什么 变量是用来存储计算机程序中的信息,唯一的目的是将数据存储在内存中. 2.Python变量的组成 变量由字母.数字.下划线组成: 变量的第一位不能是数字,可以是字母或下划线 ...

  8. CardView

    CardView继承至FrameLayout类,可以在一个卡片布局中一致性的显示内容,卡片可以包含圆角和阴影.CardView是一个Layout,可以布局其他View. CardView常用属性: c ...

  9. Tableau:数据可视化之急速BI

    1.我们通过数据可视化,是为了从数据中寻找什么呢?三个方面:模式.关系和异常.不管图形表现的是什么,我们都要留心观察这三者.

  10. windows下在文件夹中快速启动cmd

    在windows下,有时候由于特定需要,我们经常需要将cmd  cd到某文件下进行命令行操作,其实,这里有一个小技巧: 在一个文件下,按住shift键,然后点击鼠标右键,你就会发现菜单栏中多出一个“在 ...