开发者

Tabitem PreviewMouseLeftButtonDown is raised every time when mouse is pressed to the inside content. How to avoid this?

开发者 https://www.devze.com 2022-12-12 06:15 出处:网络
In WPF, I have raised PreviewMouseLeftButtonDown for a TabItem.I want this event to raise wh开发者_如何学编程en TabItem\'s header is clcked. The TabItem\'s content is a TextBox and a Button, but whene

In WPF, I have raised PreviewMouseLeftButtonDown for a TabItem. I want this event to raise wh开发者_如何学编程en TabItem's header is clcked. The TabItem's content is a TextBox and a Button, but whenever I click on the TextBox or Button, TabItem's PreviewMouseLeftButtonDown is raised. How can it be avoided?

Please help,

Thanks


This is due to tunneling in Wpf, you can stop tunneling by handling this event at root and in the handler write:

e.Handled = true;

then it will not tunnel down.

And then if you want to handle it for your textbox or button use AddHandler method to assign handler to the event instead of using normal += format.

button.AddHandler(Button.ClickEvent, new RoutedEventHandler(OnbuttonClick));

Check this for details: http://msdn.microsoft.com/en-us/library/ms742806.aspx#event_handing

0

精彩评论

暂无评论...
验证码 换一张
取 消