0

在Silverlight 3项目中,我在边框控件上使用鼠标左键按下事件,但发现事件即使在单击边界外的按钮(如5-10像素)时也会引发。Silverlight鼠标左按钮问题

有没有人遇到过这个问题?

感谢您的期待!

以下是XAML,我们正在捕捉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> 
+1

你能展示你的XAML吗? – 2010-02-16 13:54:01

+0

您确定您没有应用保证金,或者边界内的内容是否有负值? – AnthonyWJones 2010-02-16 14:26:05

+0

分享您的XAML可能会有帮助。 – funwithcoding 2010-02-16 14:45:46

回答

0

据我了解问题出在MouseLeftButtonDown事件处理。在MSDN here我发现:

MouseLeftButtonDown事件是 冒泡事件。这意味着,如果 多个的MouseLeftButtonDown事件 针对元素树, 由每个对象 在对象分层结构接收到的事件,从 ,其直接接收所述 事件,然后气泡每个 对象定义连续的父元素。 冒泡隐喻表示 事件从底部开始,并在对象树中以 的方式工作。对于冒泡事件,发件人参数 标识处理事件 的对象,而不一定是实际接收发起事件的输入 条件的对象 。

你有一个与CornerRadius="5"儿童边界。可能是这个属性实际上导致孩子边框接收鼠标事件时,视觉上不应该发生。虽然这取决于实际的实施,你最好检查一下。

+0

我试着玩brdImage和层次结构中的所有其他控件,但没有奏效。任何想法我应该寻找什么? – Haris 2010-02-19 19:28:49