I am working on a WPF application where I have a window-level Double-click event that maximizes the application window when the user double-clicks anywhere in the window. However, I also have a custom control in the application window and a separate double-click event in the user control. When a user double-clicks in a custom control, only the double-click event should be fired, and the window should not be resized. My code looks something like this:
public class Window { private void window_DoubleClick(object sender, EventArgs e) {
And my XAML looks something like this:
<Window x:class="MyProject.MyWindow" MouseDoubleClick="window_DoubleClick"> <Grid Grid.Row="0" Margin="0"> <local:myCustomControl MouseDoubleClick="myCustomControl_DoubleClick"/> </Grid> </Window>
Unfortunately, with this code in place, when the user double-clicks in the control, the control event is fired, but the Window event is also fired. I tried setting e.Handled = true in the control event, but the Window event still fires. The only thing that stopped the double-click event at the window level at startup was to handle the double-click preview using this:
private void myCustomControl_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e) { e.Handled = true; }
Although the preview event stops double-clicking the window before it can fire, I cannot use it without refactoring a good bit of code. My user control has several child controls that also handle the double-click event. If the preview event is fired at the parent control level, the double-click event never tunnels down through the child controls, and thus double-clicking does not do what I want it to do. If possible, I would like to avoid having to refactor any code in child controls. My question is: is there a way to stop the double-click event at the window level after the double-click event has been processed? I make myself crazy trying to figure it out. Any help is appreciated!
source share