WPF ScrollViewer / Canvas鼠标事件处理程序

时间:2011-12-16 14:53:56

标签: wpf scrollviewer

我创建了以下控件:

<UserControl x:Class="FooBar.AnnotationControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="400" Width="500" >
    <ScrollViewer Height="400" Width="500">
        <Canvas Height="400" Width="500" Name="ctlCanvas" MouseLeftButtonDown="MouseLeftButtonDownHandler" >
            <Canvas.RenderTransform>
                <ScaleTransform x:Name="ZoomTransform" />
            </Canvas.RenderTransform>
        </Canvas>
    </ScrollViewer>
</UserControl>

namespace FooBar
{

    public partial class AnnotationControl : UserControl
    {
        public AnnotationControl()
        {
            InitializeComponent();

        }

        private void MouseLeftButtonDownHandler( object sender, MouseButtonEventArgs args)
        {
           //Do Something
        }

    }

}

当我单击画布时,我没有在MouseLeftButtonDownHandler中点击断点。我甚至将此处理程序附加到ScrollViewer并获得相同的结果。知道这里发生了什么吗?

1 个答案:

答案 0 :(得分:1)

Canvas的默认背景是Transparent,它允许命中测试通过它。要为CanTests创建Canvas注册,请为其指定背景颜色。

<Canvas Background="White" ... />