【发布时间】:2010-09-19 05:05:37
【问题描述】:
我即将在我的地图上的每个图钉内添加模板化的<Button> 控件,以便与单击(呃,触摸)图钉的用户进行交互。这是使用图钉的正确方法吗?我不想处理 MouseDown 和 MouseUp 并重新发明一切(没有人应该这样做)。
我只需要确认。
【问题讨论】:
我即将在我的地图上的每个图钉内添加模板化的<Button> 控件,以便与单击(呃,触摸)图钉的用户进行交互。这是使用图钉的正确方法吗?我不想处理 MouseDown 和 MouseUp 并重新发明一切(没有人应该这样做)。
我只需要确认。
【问题讨论】:
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>
【讨论】:
为什么不在 MapItemsControl.ItemTemplate 中添加一个不可见的样式按钮并使用单击按钮。
【讨论】:
如果您只想点击/点击每个图钉,请将 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
}
【讨论】: