我即将在我的地图上的每个图钉中添加模板<Button>
控件,以便与用户点击(呃,触摸)图钉进行交互。这是使用图钉的正确方法吗?我不想处理MouseDown和MouseUp并重新发明所有东西(没有人应该)。
我只需要确认。
答案 0 :(得分:1)
MouseLeftBUttonUp?我只有模拟器,它适用于我的自定义图钉:
<Maps:MapItemsControl ItemsSource="{Binding Stores}">
<Maps:MapItemsControl.ItemTemplate>
<DataTemplate>
<Maps:Pushpin Location="{Binding Location}" MouseLeftButtonUp="Pushpin_MouseLeftButtonUp">
<Maps:Pushpin.Template>
<ControlTemplate TargetType="Maps:Pushpin">
<Border BorderBrush="Black" BorderThickness="1" Background="MintCream" Width="32" Height="32" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="{Binding Store.Address}" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Maps:Pushpin.Template>
</Maps:Pushpin>
</DataTemplate>
</Maps:MapItemsControl.ItemTemplate>
</Maps:MapItemsControl>
编辑:获得真实设备后,我已经测试了我的应用程序,我可以确认MouseLeftBUttonUp是一个坏主意(并不是微软在Performance tips中推荐的)
相反,你应该使用操纵事件:
<Maps:MapItemsControl ItemsSource="{Binding Stores}">
<Maps:MapItemsControl.ItemTemplate>
<DataTemplate>
<Maps:Pushpin Location="{Binding Location}" ManipulationStarted="Pushpin_ManipulationStarted">
<Maps:Pushpin.Template>
<ControlTemplate TargetType="Maps:Pushpin">
<Image Width="48" Height="48" Source="{Binding InventoryIcon}" />
</ControlTemplate>
</Maps:Pushpin.Template>
</Maps:Pushpin>
</DataTemplate>
</Maps:MapItemsControl.ItemTemplate>
</Maps:MapItemsControl>
答案 1 :(得分:0)
为什么不在MapItemsControl.ItemTemplate中添加Invisible样式按钮并使用单击按钮。
答案 2 :(得分:0)
如果您只想点击/点按每个图钉,请将MouseLeftButtonUp事件添加到您创建的每个图钉中。例如:
Microsoft.Phone.Controls.Maps.Pushpin pp = null;
System.Device.Location.GeoCoordinate loc = null;
pp = new Microsoft.Phone.Controls.Maps.Pushpin();
loc = new System.Device.Location.GeoCoordinate([Latitude], [Longitude]);
pp.Location = loc;
pp.Content = "Some Content";
pp.MouseLeftButtonUp += new MouseButtonEventHandler(Pushpin_MouseLeftButtonUp);
然后你添加
void Pushpin_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Microsoft.Phone.Controls.Maps.Pushpin tempPP = new Microsoft.Phone.Controls.Maps.Pushpin();
tempPP = (Microsoft.Phone.Controls.Maps.Pushpin)sender;
// you can check the tempPP.Content property
}