2011-05-23 46 views
0

我写了一些简单的应用程序,需要做一些事情,如果有一些鼠标左键按下事件。为什么我不能捕捉到左键单击事件?

我不明白为什么我不停止,我有方法“MouseLeftButtonDown_Event”断点

的XAML:

<UserControl 
    <Grid x:Name="LayoutRoot" Background="White" > 

     <Rectangle x:Name="RectangleTarget" Height="50" Width="50" MouseLeftButtonDown="MouseLeftButtonDown_Event" /> 


    </Grid> 
</UserControl> 
+0

您可以发布事件处理程序代码并指明您在哪里设置中断点。 – ChrisF 2011-05-23 09:40:26

+0

private void MouseLeftButtonDown_Event(object sender,MouseButtonEventArgs e) { // Do somthing } – Yanshof 2011-05-23 09:48:06

+0

使用“编辑”链接将其添加到您的问题,它将被正确格式化。 – ChrisF 2011-05-23 09:51:27

回答

2

我有一个类似的问题一次,问题是,只有最顶端的对象捕捉点击等等。在你的构造函数中试试这个,看看它是否有帮助。

LayoutRoot.AddHandler(UIElement.MouseLeftButtonDownEvent, MouseLeftButtonDown_Event, true); 

末的真正将意味着该元素将处理该事件,即使别的事情已经这样做了。

希望这会有所帮助!