tags:

views:

78

answers:

1

I have a question regarding a ComboBox in silverlight and it's selected item.

I would like to determine what triggered the SelectionChangedEvent, was it the user selecting a new item in the list or was it programatically set?

While ideally I would like to solve this using the CommandPattern (I am essentially using a modified RelayCommand (http://joshsmithonwpf.wordpress.com/2008/11/17/emulating-icommandsource-in-silverlight-2/). I am open to other suggestions.

I have also played around with the SelectionChangedEventArgs, which has an OriginalSource property, which upon first inspection may appear to help, however it is null (regardless of the manner in which the item was selected.)

Any ideas, other than setting an internal flag? :)

Thanks

A: 

Unfortunately this is a tough thing to determine, since the framework works pretty hard to simply bubble up any changes or user events in this situation as that selection changed event.

If you really need to, you could write a simple ComboBoxWrapper that is effectively the flag you're talking about - so you could derive from ComboBox, try overriding or hiding the CLR setter for SelectedItem, and then maintain state that way.

Any particular scenario in use here? There may be another way to approach a solution.

Jeff Wilcox