C# 将图钉放置在单击按钮上

C# 将图钉放置在单击按钮上,c#,wpf,wpf-controls,bing-maps,C#,Wpf,Wpf Controls,Bing Maps,我正在试图找到我应该使用什么鼠标事件在单击时放置图钉。我尝试过使用MouseUp事件,但即使我只需单击并拖动,该事件也会触发。有没有办法让鼠标只在点击时发射,而不是点击拖动?或者我还应该看另一个鼠标事件 澄清:我使用的是Bing Maps WPF控件,而不是AJAX或Silverlight。我通过处理MouseLeftButtonDown和MouseLeftButtonUp事件成功地解决了这一问题 private void map_MouseLeftButtonDown(object sende

我正在试图找到我应该使用什么鼠标事件在单击时放置
图钉
。我尝试过使用
MouseUp
事件,但即使我只需单击并拖动,该事件也会触发。有没有办法让鼠标只在点击时发射,而不是点击拖动?或者我还应该看另一个鼠标事件


澄清:我使用的是Bing Maps WPF控件,而不是AJAX或Silverlight。

我通过处理
MouseLeftButtonDown
MouseLeftButtonUp
事件成功地解决了这一问题

private void map_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    clickTimer.Start();
}

private void map_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    clickTimer.Stop();

    if (clickTimer.ElapsedMilliseconds < arbitraryConstant) // I find that 100 works well
    {
        Point mousePosition = e.GetPosition(this);
        Location pinLocation = map.ViewportPointToLocation(mousePosition);

        targetPin.Location = pinLocation;

        map.Children.Add(targetPin);
    }

    clickTimer.Reset();
}
private void map\u MouseLeftButtonDown(对象发送器,MouseButtonEventArgs e)
{
单击timer.Start();
}
私有void map_MouseLeftButtonUp(对象发送器,MouseButtonEventArgs e)
{
单击timer.Stop();
if(clickTimer.elapsedmillyseconds
Stopwatch
对象记录单击和释放单击之间经过的时间。将评估此经过的时间,并确定它是否为“单击”

警告:记住调用
单击计时器。重置()
,或者您的
秒表
对象将继续增量记录单击次数,并且只有您的第一次单击(如果您没有先单击并拖动)将触发
if


警告:不要设置
e.Handled=true
。这将阻止单击拖动事件,并且地图将无法正常平移。

有一个计时器,每次移动鼠标时都会运行该计时器。然后,当计时器完成时,接受MouseUp事件。