简体   繁体   中英

How to get text from long list selector item in Windows Phone 8?

I have a long list selector that is populated dynamically meaning the user adds items there.
This is the way items are added.

source.Add(new ShoppingList(Item1.Text));

Item1 is a textbox via which user adds stuff to the list.

I have a long list selector. Let's call it LLS. I want that when a certain itam is tapped, the text within the item is copied and pasted into a textblock.

So far I have tried the following:

string item = LLS.SelectedItems.ToString();  TextBlock.Text = item;

How can this be achieved? Thank You for your attention and answers.

ShoppingList sitem = LLS.SelectedItem as ShoppingList;
string item = string.empty;
if ( sitem != null )
{
 item = sitem. (property where you text is stored)
}

You have to subscribe to SelectionChanged Event:

private void LLS_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
  if (LLS.SelectedItem != null)
  {
     ShoppingList item = LLS.SelectedItem as ShoppingList;
     TextBlock.Text = item.yourProperty;
  }
}

BTW - there are already similar questions: one , two and probably more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM