Reputation: 25
I try to get values from an observablecollection, when the user clicks on a spezific item in a longlistselector.
obsercablecollection:
[DataContract]
public class LastList
{
[DataMember]
public string Last_Points_Name
{
get;
set;
}
[DataMember]
public double Last_Points_Position_Y
{
get;
set;
}
[DataMember]
public double Last_Points_Position_X
{
get;
set;
}
public LastList(string last_points_name, double last_points_position_y, double last_points_position_x)
{
this.Last_Points_Name = last_points_name;
this.Last_Points_Position_Y = last_points_position_y;
this.Last_Points_Position_X = last_points_position_x;
}
}
then i add items to the ObservableCollection. I then want to retrieve only the last_points_position_y and last_points_position_x values (in double format) from one spezific item (on which the user clicked)
private void SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
i am stuck here, i tried varius things like
var myItem = ((LongListSelector)sender).SelectedItem as Type;
or
string data = listsector.SelectedItem.ToString();
but i dont get the wanted result.
Upvotes: 0
Views: 1913
Reputation: 30708
try following
if(e.AddedItems != null && e.AddedItems.Length >=1)
{
var myItems = e.AddedItems[0] as LastList;
}
If there is only one selected item, myItems will have only that selected item. In case multiple selection is allowed, it will have all selected items.
Upvotes: 1