I have the following XAML sample that should raise a PreviewMouseDown (same for MouseDown) event when clicking on the Grid background:
<Window x:Class="WpfApplication1.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 PreviewMouseDown="Grid_PreviewMouseDown"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
>
<Button Margin="12,12,313,185">
Test 23
</Button>
</Grid>
</Window>
When clicking onto the button, the event gets fired, but not when I click onto the grid background.
Funny enough, when I add a background color to the grid, the event will fire on a click in the background (even when I set the color to transparent):
<Grid PreviewMouseDown="Grid_PreviewMouseDown"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="Transparent"
>
Is there a good reason for this behavior or is it the usual madness?
Many thanks for your help!