【发布时间】:2019-05-22 16:07:00
【问题描述】:
我已将 MapPolyline 添加到我的 Bing 地图。但是,地图似乎只吞噬了 LeftMouseUp 事件。该事件适用于 MouseDown 甚至 RightMouseUp,但不适用于 LeftMouseUp。对于我的设计,我必须使用 LeftMouseUp 事件并且不能使用其他事件。为什么事件没有触发,我该如何解决?
public MainWindow()
{
InitializeComponent();
var testLine = new MapPolyline();
var locations = new LocationCollection();
locations.Add(new Location(50, 50));
locations.Add(new Location(50, 60));
locations.Add(new Location(50, 70));
testLine.Locations = locations;
testLine.Stroke = Brushes.Black;
testLine.StrokeThickness = 15;
testLine.PreviewMouseDown += ExampleHandlerDown;
testLine.PreviewMouseUp += ExampleHandlerUp;
MainMap.Children.Add(testLine);
}
private void ExampleHandlerDown(object sender, MouseEventArgs e)
{
Console.WriteLine("Mouse Down");
}
private void ExampleHandlerUp(object sender, MouseEventArgs e)
{
Console.WriteLine("Mouse Up");
}
<Window x:Class="StackQuestion.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
mc:Ignorable="d"
Title="MainWindow" Height="700" Width="1300">
<m:Map Name="MainMap" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CredentialsProvider="My Credentials"/>
</Window>
运行代码有以下结果: - 鼠标左键单击仅打印“鼠标向下” - 鼠标右键单击打印“鼠标向下”和“鼠标向上” 鼠标左键单击应与鼠标右键单击行为匹配。
【问题讨论】:
-
尝试使用 PreviewMouseUp/Down。
-
我刚做了,结果一样。