Ayman
Ayman

Reputation: 1463

Get event trigger

I am using WPF ListBox, binding the ItemsSource to an ObservableCollection.

I subscribed to the SelectionChanged event, which will notify me when the user select/deselect any ListItem.

Now, can I get whether the selection in the ListBox was changed due to user click or Collection change (i.e. items were removed from the Collection which were selected in the ListBox) ??

Upvotes: 0

Views: 34

Answers (1)

Sheridan
Sheridan

Reputation: 69959

As you know when you remove some items from the collection, you could set a bool flag as you remove something and then ignore calls to the handler when the flag is true... of course, don't forget to set the flag to false again afterwards:

isProgramAction = true;
Items.Remove(item);
isProgramAction = false;

...

private void SelectionChanged(object sender, RoutedEventArgs e)
{
    if (!isProgramAction) 
    {
        // User Action
    }
} 

Upvotes: 1

Related Questions