Is there a way to order this silverlight bound ListBox. I am not sure the way I have populated makes it easy?
Code sample here:
XElement _xml = XElement.Load("MSA.xml");
{
msa.Items.Clear();
foreach (XElement value in _xml.Elements("channel").Elements("msa"))
{
MSAFeedItem _item = new MSAFeedItem();
_item.Lat = double.Parse(value.Element("lat").Value);
_item.Long = double.Parse(value.Element("long").Value);
_item.Name = value.Element("n").Value;
double dis1 = _item.Lat - curLatitude;
double dis2 = _item.Long - curLongitude;
var miles1 = Math.Pow(dis1, 2.0);
var miles2 = Math.Pow(dis2, 2.0);
var miles3 = miles1 + miles2;
var miles4 = Math.Sqrt(miles3) ;
var miles = miles4 * 62.1371192;
_item.Distance = Decimal.Truncate(Convert.ToDecimal(miles));
msa.Items.Add(_item);
}
}
It needs to be in ascending order according to a double or decimal value called ‘miles’
ListBox is called ‘msa’
Many thanks for any help or suggestions.
EDIT: Ive added my distance code to help you understand whats going on, so _item.distance or ‘miles’ is the number it needs to ascend by.
The code is a bit messy and doesnt work exactly rightt but you get the idea.
1 Answer