Silverlight鼠标左键按下问题

发布于 2024-08-21 12:30:19 字数 1886 浏览 3 评论 0原文

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软糖 2024-08-28 12:30:19

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

MouseLeftButtonDown 事件是
冒泡事件。这意味着如果
多个 MouseLeftButtonDown 事件
为元素树定义,
事件被每个对象接收
在对象层次结构中,从
直接接收的对象
事件,然后冒泡到每个
连续的父元素。

冒泡的比喻表明
事件从底部开始并起作用
它沿着对象树向上。对于一个
冒泡事件,sender参数
标识事件所在的对象
被处理,不一定是对象
实际收到输入的
启动事件的条件。

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文