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
精彩评论