2

I'm wondering how I can get the "selected"Item on hold event on a grouped longlistselector in WindowsPhone 8 in C#.

I've already read eg. the following Hold Event Longlistselector

But this does not seem to work with a grouped Longlistselector.

Because of the Grouping, the DataContext of my LongListSelector is a List of Lists of the displayed items. Can I somehow access the item on which the hold-event occured?

(Or am I wrong at filling the grouped LongListSelector?)

Community
  • 1
  • 1
malte
  • 1,171
  • 1
  • 15
  • 28

1 Answers1

1

In my code, I can get selected item from grouped LLS like this:

private void LLST_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
   if (LLST.SelectedItem != null)
   {
      ItemType item = LLST.SelectedItem as ItemType;
      // do some stuff
   }
}

If it's not working, maybe you can show some more code.

EDIT

Note also that hold event doesn't select it (that's maybe why it's not working in your code as you expect it). Check if hold works after selecting item with a tap first. You can read some more here.

Community
  • 1
  • 1
Romasz
  • 29,662
  • 13
  • 79
  • 154
  • Thanks for answering. Unfortunately in my case (I think it should be general behaviour?!) an item only gets selected on tap/click event and not on hold. Therefore my SelectedItem ist always null. I'll update my question with some more code later when I'm back home. – malte Dec 23 '13 at 09:16
  • @malte I've updated my answer, maybe it will help a little more. – Romasz Dec 23 '13 at 09:29
  • Brilliant! the e.OriginalSource (linked in your 'further reading') was the key for me here. It's nice to know that it returns the element which is at the top (directly under your finger) :) – malte Dec 23 '13 at 10:12