현재이 코드를 사용하여 XML 파일을 기반으로 여러 압핀을 사용하지 않습니다. 압정을위한 onclick 이벤트도 있습니다. 하지만 내가하고 싶은 것은 Name
var을 각 고정 핀에서 다른 페이지로 패스하는 것입니다.압정 버튼을 눌렀을 때 변수를 전달하는 방법?
나는 그것이 작동 할 것이라고 생각하는 방식으로 설정했지만 값은 전달되지 않고 메시지 상자는 각 정지 지점의 번호를 표시하지 않습니다. 그러나 내가 pushpin의 내용을 root.Name으로 설정하면 번호가 압정에 잘 표시됩니다.
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);
foreach (var root in Transitresults)
{
var accentBrush = (Brush)Application.Current.Resources["PhoneAccentBrush"];
var pin = new Pushpin
{
Location = new GeoCoordinate
{
Latitude = root.Lat,
Longitude = root.Lon
},
Background = accentBrush,
Content = root.Name,
Tag = root,
};
pin.MouseLeftButtonUp += BusStop_MouseLeftButtonUp;
BusStopLayer.AddChild(pin, pin.Location);
}
}
void BusStop_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
var bNumb = ((FrameworkElement)sender);
if (bNumb != null)
{
// Here is would like to pass the Name element from var transitresults to another page.
// The element Name is different for each pushpin and is parses from the XML
}
}
// 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; }
}
실제로 컴파일 할 수 있도록 코드를 정리할 수 있습니까? 예를 들어 이벤트 코드에서 루트를 사용하고 있지만 bNumb을 의미한다고 생각하십니까? – AnthonyWJones
@AnthonyWJones bNumb.Name은 루트에서 파싱 된 이름이 아니라 속성 이름이나 bNUmb를 가리 키기 때문에 잘못되었습니다. – Rhys
질문은 여전히 혼란 스럽습니다. 이벤트 핸들러는 ID를 정적 문자열로 하드 코딩하므로 "메시지 상자가 각 정류장의 번호를 표시하지 않음"이란 무엇을 의미합니까? – Bryant