void LoadFromXML(DataTemplate planeTemplate) { XDocument document = DataLoader.LoadXmlFromResources("/Data/FlightMap.xml"); if (document != null) { foreach (XElement element in document.Element("Planes").Elements()) { List <GeoPoint> points = new List <GeoPoint>(); foreach (XElement infoElement in element.Element("Path").Elements()) { GeoPoint geoPoint = new GeoPoint(Convert.ToDouble(infoElement.Element("Latitude").Value, CultureInfo.InvariantCulture), Convert.ToDouble(infoElement.Element("Longitude").Value, CultureInfo.InvariantCulture)); points.Add(geoPoint); } PlaneInfo info = new PlaneInfo(element.Element("PlaneName").Value, element.Element("PlaneID").Value, element.Element("EndPointName").Value, element.Element("StartPointName").Value, Convert.ToInt32(element.Element("Speed").Value), Convert.ToInt32(element.Element("Altitude").Value), points); info.CurrentFlightTime = Convert.ToDouble(element.Element("CurrentFlightTime").Value, CultureInfo.InvariantCulture); planesInfo.Add(info); } } foreach (PlaneInfo info in planesInfo) { MapCustomElement mapCustomElement = new MapCustomElement() { Content = info, ContentTemplate = planeTemplate }; BindingOperations.SetBinding(mapCustomElement, MapCustomElement.LocationProperty, new Binding("Position") { Source = info }); Planes.Add(mapCustomElement); AddPaths(info); } }
void AddPaths(PlaneInfo planeInfo) { if (planeInfo != null) { foreach (MapItem item in planeInfo.GetAirPath(airportTemplate)) { BindingOperations.SetBinding(item, MapItem.VisibleProperty, new Binding("SelectedPlaneInfo") { Source = this, Converter = new PlaneInfoToPathVisibilityConverter(), ConverterParameter = item.Tag }); ActualAirPaths.Add(item); } } }
void LoadFromXML() { XDocument document = DataLoader.LoadXmlFromResources("/Data/FlightMap.xml"); if (document != null) { foreach (XElement element in document.Element("Planes").Elements()) { List <GeoPoint> points = new List <GeoPoint>(); foreach (XElement infoElement in element.Element("Path").Elements()) { GeoPoint geoPoint = new GeoPoint(Convert.ToDouble(infoElement.Element("Latitude").Value, CultureInfo.InvariantCulture), Convert.ToDouble(infoElement.Element("Longitude").Value, CultureInfo.InvariantCulture)); points.Add(geoPoint); } PlaneInfo info = ViewModelSource.Create(() => new PlaneInfo(element.Element("PlaneName").Value, element.Element("PlaneID").Value, element.Element("EndPointName").Value, element.Element("StartPointName").Value, Convert.ToInt32(element.Element("Speed").Value), Convert.ToInt32(element.Element("Altitude").Value), points)); info.CurrentFlightTime = Convert.ToDouble(element.Element("CurrentFlightTime").Value, CultureInfo.InvariantCulture); planesInfo.Add(info); } } Planes = planesInfo; }