この画鋲のバインディングに頭を悩ませているようには見えないので、もう少し助けが必要です。
XMLから解析し、Lat、Lon、Altで座標文字列を分割する次のコードがあります。私がやりたいのは、これらのポイントをBingMapに画鋲として表示することです。
でGeocoordinatesの新しいオブジェクトを作成することで、Location
それを画鋲の位置にバインドできると思いましたが、何も表示されません。どこが間違っているのですか?
namespace Pushpins_Itemsource
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
WebClient busStops = new WebClient();
busStops.DownloadStringCompleted += new DownloadStringCompletedEventHandler(busStops_DownloadStringCompleted);
busStops.DownloadStringAsync(new Uri("http://www.domain/source.xml"));
}
void busStops_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
return;
var busStopInfo = XDocument.Load("Content/BusStops2.xml");
var Transitresults = from root in busStopInfo.Descendants("Placemark")
let StoplocationE1 = root.Element("Point").Element("coordinates")
let nameE1 = root.Element("name")
select new TransitVariables
(StoplocationE1 == null ? null : StoplocationE1.Value,
nameE1 == null ? null : nameE1.Value);
}
// Add properties to your class
public class TransitVariables
{
// Add a constructor:
public TransitVariables(string stopLocation, string name)
{
this.StopLocation = stopLocation;
this.Name = name;
if (!string.IsNullOrEmpty(StopLocation))
{
var items = stopLocation.Split(',');
this.Lon = double.Parse(items[0]);
this.Lat = double.Parse(items[1]);
this.Alt = double.Parse(items[2]);
}
}
public string StopLocation { get; set; }
public string Name { get; set; }
public double Lat { get; set; }
public double Lon { get; set; }
public double Alt { get; set; }
}
public class TransitViewModel
{
ObservableCollection<TransitVariables> Transitresults ;
public ObservableCollection<TransitVariables> TransitCollection
{
get { return Transitresults; }
}
}
}
}
XAMLは次のようになります。
<my:Map ZoomLevel="6" Height="500" HorizontalAlignment="Left" Margin="0,6,0,0" CopyrightVisibility="Collapsed" LogoVisibility="Collapsed" Name="Map" VerticalAlignment="Top" Width="456">
<my:MapItemsControl ItemsSource="{Binding TransitVariables}" Height="494">
<my:MapItemsControl.ItemTemplate>
<DataTemplate>
<my:Pushpin Location="{Binding Location}" />
</DataTemplate>
</my:MapItemsControl.ItemTemplate>
</my:MapItemsControl>
</my:Map>