KirillOsenkov / PublicBugs

My personal bug tracker for products where it's not worth logging a bug in their tracker
MIT License
0 stars 0 forks source link

TreeViewItem.DoubleClick event continues to bubble even if e.Handled is set to true #4

Open KirillOsenkov opened 7 years ago

KirillOsenkov commented 7 years ago

DevDiv 207228

http://stackoverflow.com/a/36244243/37899

The bug seems to be in this code in WPF: http://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Controls/Control.cs,5ed30e0aec6a58b2

It receives the MouseLeftButtonDown event (which is handled by the child control already), but it fails to check if e.Handled is already set to true. Then it proceeds to create a new MouseDoubleClick event args (with e.Handled == false) and invokes that always.

The question also remains why after having set it to handled the first time the event continues to bubble? Because in this line, when we register the handler Control.HandleDoubleClick: http://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Controls/Control.cs,40 we pass true as the last argument to RegisterClassHandler: http://referencesource.microsoft.com/#PresentationCore/Core/CSharp/System/Windows/EventManager.cs,161 which is handledEventsToo.

So the unfortunate behavior is a confluence of two factors: 1.Control.HandleDoubleClick is called always (for handled events too), and 2.Control.HandleDoubleClick fails to check if the event had already been handled