What is the correct event to capture "Click" in a ListBox on Windows Phone 7?

I am writing a Windows Phone 7 application with a ListBox. When an item in a ListBox “clicks” or “swings” with its finger, what is the appropriate event for this?

I tried "SelectedIndexChanged", but it is like running GoBack () when the application is TombStoned and index 0 is passed (which seems weird).

I am currently using MouseUp, which seems to do the trick. But I'm not sure if this is correct.

Note. I discovered the reason SelectionChanged started when clicked. When the Constructor was launched for my page, and an ItemSouce for my ListBox was set (data binding), which would select the first item in the list and fire the SelectionChanved event. Since this was not triggered by user action, I solved this by simply creating a boolean value of IsLoaded and setting it to true after setting the ItemSource in the constructor and then checking it in the event.

+3
source share
1 answer

If you want to be notified when an item is selected, you must catch the SelectionChanged event.

In the handler, you verify that e.AddedItems contains exactly one element:

void SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (e.AddedItems.Count == 1)
    {
        // .. do something
    }
}

GoBack() , , e.RemovedItems, e.AddedItems.

+2

Source: https://habr.com/ru/post/1784465/


All Articles