views:

545

answers:

1

Hi, In a Silverlight 3 project I am using mouse left button down event on a border control but found out that the event is raised even when I click the button slightly outside the border like 5-10 pixels.

Has anyone faced this issue before?

Thanks in anticipation!

Following is the XAML in which we are capturing the event of brdSelect:

        <Border  MouseLeftButtonDown="Grid_Mousedown" x:Name="brdSelect" Grid.Row="1" Grid.Column="1" BorderThickness="0.5" BorderBrush="#FF2D9FD2">
            <Grid x:Name="grdSelect" >

                <Border x:Name="brdImage"   BorderThickness="0" CornerRadius="5" Width="Auto" Height="Auto">
                   <Image Height="Auto" Width="Auto" Stretch="UniformToFill" x:Name="imgMotive"/>
                </Border>

                <Image Height="Auto" Stretch="UniformToFill" x:Name="imgtmp" Visibility="Collapsed"/>

            </Grid>
        </Border>

        <Image Height="13" Width="13" Source="../Images/rotate_small.JPG" Stretch="None" x:Name="imgRotate" Grid.Row="0" Grid.Column="3" Visibility="Collapsed"/>
        <StackPanel Orientation="Horizontal" d:LayoutOverrides="GridBox" Grid.ColumnSpan="3" Margin="0,0,2,0" Width="32" HorizontalAlignment="Left">
            <Image Height="13" Width="13" Source="../Images/delete_small.JPG" Stretch="None" x:Name="imgDelete"  Visibility="Collapsed" />
        </StackPanel>
        <Image Source="../Images/resize_small.JPG" Stretch="None" x:Name="imgResize" Grid.Row="2" Grid.RowSpan="2"  Grid.Column="2" Visibility="Collapsed" Opacity="0"/>

    </Grid>
    <TextBlock x:Name="txtLabel" Height="100" HorizontalAlignment="Left" Margin="-80,0,0,-20" Width="80" Text="X: 0 --- Y: 0" Foreground="Red" TextWrapping="Wrap" Visibility="Collapsed"/>

</Grid>
</Border>
A: 

As I understand the problem is in MouseLeftButtonDown event handling. In MSDN here I found:

The MouseLeftButtonDown event is a bubbling event. This means that if multiple MouseLeftButtonDown events are defined for a tree of elements, the event is received by each object in the object hierarchy, starting with the object that directly receives the event, and then bubbles to each successive parent element. The bubbling metaphor indicates that the event starts at the bottom and works its way up the object tree. For a bubbling event, the sender parameter identifies the object where the event is handled, not necessarily the object that actually received the input condition that initiated the event.

You have a child border with CornerRadius="5". May be this property actually causes child border to receive mouse event when visually this should not happen. Although this depends on actual implementation and you'd better check this.

terR0Q
I tried playing with brdImage and all other controls in hierarchy but didnt work. Any ideas what I should look for?
Haris