static void CityInfoPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { CityInformationControl control = d as CityInformationControl; if (control != null && !e.NewValue.Equals(e.OldValue)) { control.StartImageChanging(); } }
void LoadDataFromXML(DataTemplate citySmallIconTemplate) { XDocument document = DataLoader.LoadFromXmlResource("MapDemo/Data/CitiesData.xml"); if (document != null) { foreach (XElement element in document.Element("Cities").Elements()) { string cityName = element.Element("CityName").Value; GeoPoint cityLocation = new GeoPoint(Convert.ToDouble(element.Element("Latitude").Value, CultureInfo.InvariantCulture), Convert.ToDouble(element.Element("Longitude").Value, CultureInfo.InvariantCulture)); CityInfo cityInfo = new CityInfo(cityName, cityLocation); foreach (XElement placeElement in element.Element("Places").Elements()) { string placeName = placeElement.Element("Name").Value; GeoPoint placeLocation = new GeoPoint(Convert.ToDouble(placeElement.Element("Latitude").Value, CultureInfo.InvariantCulture), Convert.ToDouble(placeElement.Element("Longitude").Value, CultureInfo.InvariantCulture)); string placeDescription = placeElement.Element("Description").Value; Uri placeImageUri = new Uri(placeElement.Element("ImageUri").Value, UriKind.RelativeOrAbsolute); BitmapImage image = new BitmapImage(placeImageUri); cityInfo.Places.Add(new PlaceInfo(placeName, cityName, placeLocation, placeDescription, image)); } CityInformationControl city = new CityInformationControl() { CityInfo = cityInfo }; Binding binding = new Binding() { Path = new PropertyPath("IsMapView"), Source = this }; city.SetBinding(CityInformationControl.VisibleProperty, binding); MapCustomElement mapItem = new MapCustomElement() { Content = city, Location = cityLocation }; mapItem.PointerReleased += OnPointerReleased; mapItem.PointerPressed += OnPointerPressed; Cities.Add(mapItem); CitySmallIcons.Add(new MapCustomElement() { Content = cityInfo, ContentTemplate = citySmallIconTemplate, Location = cityInfo.Location }); } } }