SelectionChanged event

Apr 25, 2014 at 1:36 PM
Hi, I was looking for some event (like SelectionChanged), but I didn't find any. Maybe there is another way to be notified in such case?
Thank you
Coordinator
Apr 30, 2014 at 9:29 AM
The SelectedItems-Collection is an observable collection. You can subscribe to NotifyCollectionChanged.

Regards!
Apr 30, 2014 at 2:11 PM
Thank you!
Still, the NotifyCollectionChanged.CollectionChanged is being fired "too frequently" ;)
On single selection change it could be fired several times... with NotifyCollectionChangedAction.Add and with NotifyCollectionChangedAction.Remove
I made some changes in TreeViewEx code to fit my needs with new event "SelectionChanged", but since I am not a TreeViewEx developer I cannot check-in my changes...
Best regards,
A.
Coordinator
May 5, 2014 at 11:45 AM
Then we should solve the problem of the collection firing to often instead of introducing a new event. In which cases does that happen?
May 12, 2014 at 8:05 AM
OK, let me explain...

I did this:
System.Collections.Specialized.INotifyCollectionChanged incol = this.tree.SelectedItems as System.Collections.Specialized.INotifyCollectionChanged;
if (incol != null)
{
  incol.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(incol_CollectionChanged);
}

void incol_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
  System.Console.WriteLine("CollectionChanged: {0}", e.Action);
}
Imagine you have several items selected and then you suddenly click on single item so there will be only one item selected there...
This is the output:
CollectionChanged: Remove
CollectionChanged: Remove
CollectionChanged: Remove
CollectionChanged: Add
So I'd rather have a single callback function call informing that the selection was changed than 4 (multiple)...
...and even the MS TreeView control is having such event...
public event RoutedPropertyChangedEventHandler<object> SelectedItemChanged;