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

MouseDown not triggered?

系統 2064 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免费在线观看 | 国模极品一区二区三区 | 伊人久久综合谁合综合久久 | 国产精品蜜臀 | 91成人啪国产啪永久地址 | 久热精品免费视频 | 色91在线| 极品福利| 亚洲成精品动漫久久精久 | 欧美性色生活片天天看99 | 中文字幕欧美日韩 | 精品国产免费一区二区三区 | 激情综合视频 | 久久精品无码一区二区日韩av | 夜夜躁狠狠躁日日躁2021 | 在线日本中文字幕 | 国产综合色在线视频播放线视 | 青青青青青国产免费观看 | 国产成人亚洲精品 | 福利视频免费看 | 日韩视频 中文字幕 | 四虎永久免费网站 | 91在线看视频| 免费黄色小视频在线观看 | 香蕉久久精品 | 欧美13一14周岁a在线播放 | 欧美成年黄网站色高清视频 | 激情五月宗合网 | 99久久国内精品成人免费 | 国产全黄a一级毛片视频 | 国产swag在线观看 | 91视频第一页 | 免费观看视频成人国产 | 福利视频999 | 久久99国产精品久久欧美 | 中文字幕91在线 | 国产午夜不卡 | tobesex日本护士 | 激情综合婷婷亚洲图片 | 91在线精品老司机免费播放 | 毛片网站视频 |