ユーザーが wp7 アプリの Bing マップで複数の画鋲を表示できるようにするシナリオがあります。maplayer を使用して画鋲のクラスターを作成しましたが、cs ファイル自体でその画鋲に画像を動的に追加することはできませんでした。ちなみに、xamlで画鋲コントロールは使っていません。ループ中に画鋲オブジェクトを maplayer に追加しているだけです。
これが私のコードです:
maplayer layer = new maplayer();
watcher.start();
for (int i = 0; i < lst.count; i++)
{
Pushpin mypin = new Pushpin();
watcher.Position.Location.Latitude = Convert.ToDouble(lst[i].Latitude);
watcher.Position.Location.Longitude=Convert.ToDouble(lst[i].Longitude);
}
GeoCoordinate geo = new GeoCoordinate(watcher.Position.Location.Latitude, watcher.Position.Location.Longitude);
mypin.Location = geo;
mypin.Background = new SolidColorBrush(Colors.Gray);
mypin.Foreground = new SolidColorBrush(Colors.White);
mypin.Content = "My location";
layer.AddChild(mypin, mypin.Location);
}
map1.SetView(watcher.Position.Location, Status == true ? 5.0 : 3.0);
map1.Children.Add(layer);
watcher.stop();
また、画像ブラシ プロパティを使用して画鋲に画像ソースを提供しようとしましたが、画鋲自体が見えなくなります。
このような:
ImageBrush ib = new ImageBrush();
ib.ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri(@"Images/push.png", UriKind.Relative));
mypin.Background = ib;
これについて私を助けてください。xaml側からデータテンプレートをプッシュピンに変更/追加せずにこれを行う必要があります。