【问题标题】:Silverlight mouse left button down issueSilverlight 鼠标左键按下问题
【发布时间】:2010-02-16 13:33:54
【问题描述】:

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

以前有人遇到过这个问题吗?

感谢期待!

以下是我们在其中捕获 brdSelect 事件的 XAML:

        <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>

【问题讨论】:

  • 您确定您还没有应用边距,或者边框内的内容具有负边距吗?
  • 分享您的 XAML 可能会有所帮助。

标签: silverlight silverlight-3.0 mouseevent mouseleftbuttondown


【解决方案1】:

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

MouseLeftButtonDown 事件是一个 冒泡事件。这意味着如果 多个 MouseLeftButtonDown 事件 为元素树定义, 事件被每个对象接收 在对象层次结构中,从 直接接收的对象 事件,然后冒泡到每个 连续的父元素。 冒泡比喻表明 事件从底部开始并且有效 它沿着对象树向上。为一个 冒泡事件,sender参数 标识事件所在的对象 被处理,不一定是对象 实际收到输入的 触发事件的条件。

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

【讨论】:

  • 我尝试使用 brdImage 和层次结构中的所有其他控件,但没有奏效。我应该寻找什么想法?
猜你喜欢
  • 2011-04-26
  • 2011-02-28
  • 2011-06-17
  • 1970-01-01
  • 1970-01-01
  • 2010-09-27
  • 1970-01-01
  • 1970-01-01
  • 2015-05-06
相关资源
最近更新 更多