亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

MouseDown not triggered?

系統 1822 0

In following case:

< Window x : Class ="WpfApplication59.MainWindow"

xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns : x ="http://schemas.microsoft.com/winfx/2006/xaml"

Title ="MainWindow" Height ="350" Width ="525">

< Grid >

< Button HorizontalAlignment ="Center" VerticalAlignment ="Center" MouseDown ="Button_MouseDown"> test </ Button >

</ Grid >

</ Window >

?

public partial class MainWindow : Window

{

public MainWindow()

{

InitializeComponent();

this .AddHandler( Button .MouseDownEvent, new MouseButtonEventHandler (Test), true );

}

?

private void Button_MouseDown( object sender, MouseButtonEventArgs e)

{

Console .WriteLine( "mousedown from button." );

}

?

private void Test( object sender, MouseButtonEventArgs e)

{

Console .WriteLine( "mousedown from test." );

}

}

?

The Button_MouseDown cannot be triggered, because MouseDown is a "bubbling" event, it means that child control on which the event happens handles it first, and only if it
declines to handle it, the event is passed on to the parent of that
control (and so on, until it reaches top). If you want to capture the
event in a parent before the child sees it, you need to use a
"tunneling" event - in your case, it would be PreviewMouseDown.

?

As an alternative approach suggested is adding the line
AddHandler(FrameworkElement.MouseDownEvent, new
MouseButtonEventHandler(Test), true);
to your window's constructor after the call to InitializeComponent (and
remove "MouseDown="Button_MouseDown" from the XAML).

Below is the mainwindow:

MouseDown not triggered?

Click test button, see how the events were handled from snoop:

MouseDown not triggered?

First the preview… event is raised, then mousedown event raised, since the mousedown is already handled by button, so you cannot listen it outside.

?

?

MouseDown not triggered?


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 日韩精品中文字幕一区二区三区 | 亚洲精品免费在线 | 91精品国产福利尤物 | 国产一区二区在线观看视频 | 欧美一级片 在线播放 | 欧美国产日韩久久久 | www.久久综合| 久久综合一区二区三区 | 久久93精品国产91久久综合 | 久久女同互慰一区二区三区 | 日本不卡在线一区二区三区视频 | 国产一级一级毛片 | 国产一区亚洲二区 | 毛片网站免费在线观看 | 久久这里只有精品免费看青草 | 欧美成人精品福利在线视频 | 亚洲两性 | 日本免费特黄aa毛片 | 一级毛片在线免费观看 | 国产a视频 | 成人a毛片视频免费看 | 国产精品资源站 | 欧美怡红院免费全部视频 | 天天夜夜骑 | 蕾丝视频在线看片国产 | 国产精品永久免费视频 | 在线欧美69v免费观看视频 | 四虎永久在线精品影院 | 十级毛片 | 色综合亚洲天天综合网站 | 国产午夜精品久久理论片 | 欧美啊v在线观看 | 国产精品福利久久2020 | 狠狠综合久久综合网站 | 国产伦精品一区二区三区女 | 亚洲系列在线 | 亚洲天天做夜夜做天天欢人人 | 国产在线精品一区免费香蕉 | 久久爱综合久久爱com | 国产精品视频免费一区二区三区 | 久久久久国产精品四虎 |