我正在尝试将命令绑定到毛伊岛地图上的标记单击事件。我使用 DataTemplate 绑定了引脚。我可以通过 MainPage.xaml.cs 让它工作,但我的应用程序正在使用 viewModel。我无法绑定事件。
<maps:Map x:Name="map" IsShowingUser="true" ItemsSource="{Binding SavedSpots}" >
<maps:Map.ItemTemplate>
<DataTemplate>
<maps:Pin Location="{Binding Location}"
Address="{Binding Address}"
Label="{Binding Label}"
MarkerClicked="{Binding Pin_MarkerClicked}">
</maps:Pin>
</DataTemplate>
</maps:Map.ItemTemplate>
</maps:Map>
我尝试了CommunityToolkit EventToCommandBehavior,但地图没有任何行为。
任何帮助都会很棒。 谢谢
<maps:Map x:Name="map" IsShowingUser="true" ItemsSource="{Binding SavedSpots}" >
<maps:Map.ItemTemplate>
<DataTemplate>
<maps:Pin Location="{Binding Location}"
Address="{Binding Address}"
Label="{Binding Label}">
<maps:Pin.Behaviors>
<mct:EventToCommandBehavior Command="{Binding MarkerClickedCommand}" EventName="MarkerClicked" />
</maps:Pin.Behaviors>
</maps:Pin>
</DataTemplate>
</maps:Map.ItemTemplate>
</maps:Map>
我在类型 pin 中找不到行为
<maps:Map x:Name="map" IsShowingUser="true" ItemsSource="{Binding SavedSpots}">
<maps:Map.Behaviors>
<mct:EventToCommandBehavior Command="{Binding MarkerClickedCommand}" EventName="MarkerClicked" />
</maps:Map.Behaviors>
<maps:Map.ItemTemplate>
<DataTemplate>
<maps:Pin Location="{Binding Location}"
Address="{Binding Address}"
Label="{Binding Label}">
</maps:Pin>
</DataTemplate>
</maps:Map.ItemTemplate>
</maps:Map>
我也尝试过这个,但应用程序无法运行。 System.Reflection.TargetInitationException:“调用目标已引发异常。”