tags:

views:

29

answers:

1

I have following grid:

<Grid x:Name="grd" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Height="100" >
    <Button x:Name="but" OverridesDefaultStyle="True" Width="50" Height="50" HorizontalAlignment="Left" VerticalAlignment="Top"  >
    <Button.Template>
        <ControlTemplate TargetType="{x:Type Button}">
            <Border Name="Bd" Style="{StaticResource MatrixStyle}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="50" Height="50" />

        </ControlTemplate>
    </Button.Template>
    </Button>
    <Border BorderBrush="Black" BorderThickness="1" Width="50" Height="50" HorizontalAlignment="Left" VerticalAlignment="Top"/>
    <Border BorderBrush="Black" BorderThickness="1" Width="50" Height="50" HorizontalAlignment="Right" VerticalAlignment="Top"/>
    <Border BorderBrush="Black" BorderThickness="1" Width="50" Height="50" HorizontalAlignment="Left" VerticalAlignment="Bottom"/>
    <Border BorderBrush="Black" BorderThickness="1" Width="50" Height="50" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>     
    </Grid>

This parent grid has MouseDown event attached to it. If I keep the 4 Borders and remove the buttons this event gets fired.But If I keep only the button and remove the other borders this event does not get fired. what may be the probable cause of this problem?

+1  A: 

The Button handles the MouseDown event and "consumes" it (i.e. it prevents it from routing up further to its parent by setting "e.Handled = true" for the MouseDown event). Thus, it doesn't reach your Grid control.

Having said that, you might want to handle the PreviewMouseDown event instead. This one gets fired first in the Grid before it reaches the Button so you'll surely be able to handle it on the Grid.

karmicpuppet
I have handled PreviewMouseDown event at the grid level. Now I want to handle MouseDown event at the button level. How to do that? Note: I Have set e.Handled = false at the PreviewMouseDown eventhandler.
munna