wierd behaviour when updating observable collection from subscribed event..

Oct 22, 2008 at 8:49 PM
Edited Oct 22, 2008 at 8:51 PM

I am getting  really wierd multiple selections in a listbox bound to an observable collection that is added to on receipt of an event.. selecting one item in the listbox can cause numerous (seemingly random) other entries to be selected even though the listbox is set to single selection mode.

I have a Presentation Model that contains an observable collection that is bound to by a list box.

private observable collection:
    private readonly ObservableCollection<string> _importEvents = new ObservableCollection<string>();

public property bound to by xaml
        public ObservableCollection<string> ImportEvents
            get { return _importEvents; }

In the constructor for my Presentation model I subscribe to an event, on receipt of event I add to the observable collection (on the UI thread)

_eventAggregator.GetEvent<FileImportEvent>().Subscribe(EventText => _importEvents.Add(EventText), ThreadOption.UIThread);

Is there something fundamentaly wrong that I am doing?

I have tried filling the collection with static data on construction and this all selects fine, it is only when I select the dynamically added entries that things go all Xfiles on me :-)

My presentation model on receiving a call from a button click event handler is calling via interface to code which
1) first publishes a 'FileImportEvent'  via the aggregator to say it has been invoked,
2) it then kicks off a seperate process and waits for process completion or timeout
3) then publishes further events to describe process completion results
4) returns to the caller. 

I was originaly running the seperate process asynchronously and publishing the 'FileImportEvent' on Process.Exited, when I came across this issue I though it was due to the multiple threads publishing the events.. (although I thought the event agregator must marshal events when the subscriber requests them on the UIThread?)

I have looked at the collection in the debugger and that seems fine, I have visualized the UI using mole and the listbox simply shows multple entries showing selected = true.. I can work round this by dropping the listbox (listview does the same thing so it would have to be a text box).. or switching to feeding back via an interface, I am just extremely curious to know what I have missunderstood..

any input welcome.