我要在我的地圖上的每個我的圖釘內添加模板<Button>
控件,以便與用戶點擊(呃,觸摸)圖釘。這是使用圖釘工作的正確方法嗎?我不想處理MouseDown和MouseUp並重新創建所有內容(而且沒有人應該)。我應該如何處理我的必應地圖控件中的圖釘上的點擊事件WP7
我只需要確認。
我要在我的地圖上的每個我的圖釘內添加模板<Button>
控件,以便與用戶點擊(呃,觸摸)圖釘。這是使用圖釘工作的正確方法嗎?我不想處理MouseDown和MouseUp並重新創建所有內容(而且沒有人應該)。我應該如何處理我的必應地圖控件中的圖釘上的點擊事件WP7
我只需要確認。
爲什麼你不在MapItemsControl.ItemTemplate中添加一個隱藏式樣式的按鈕並使用單擊按鈕。
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是一個壞主意(以及Microsoft不推薦後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>
我建議一個不可見的按鈕,而不是操縱/ MouseDown是因爲Button.Click是非常標準的用戶體驗,並且很容易讓程序員來處理它。我需要我的事件纔會觸發一次,我有一個MouseDown + MouseUp這是一個Click :) – 2010-12-06 06:32:20
如果你想要的是能夠點擊/ TAP每個圖釘,一個的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
}
是啊,我的問題已經「
對我來說工作很不錯。 – 2010-09-19 23:23:41
添加一個不可見的按鈕,當你有真正的事件,因爲它似乎不必要 – MatthieuGD 2010-12-04 16:20:46