I am having an issue where my ObservableCollection is not updating the view. I can place a breakpoint prior to the OnPropertyChange and can verify that my collection has the names in them.
In my model i have a event that fires a List with random names in it.
in my view model i subscribe to this event and my event handler does this
void _manager_ProcessesChanged(List<string> n)
{
//create a new collection to hold current Ids
ObservableCollection<string> names = new ObservableCollection<string>();
//copy ids into our collection
foreach (string name in n)
{
names.Add(name);
}
Names = names;
}
my Names property looks like so
ObservableCollection<string> _names = new ObservableCollection<string>();
public ObservableCollection<string> Names
{
get { return _names; }
set
{
_names = value;
OnPropertyChanged("Names");
}
}
and my view binds looks like this
<Window.DataContext>
<vm:MainWindowViewModel/>
</Window.DataContext>
<Grid>
<ListBox ItemsSource="{Binding Path=Names}"/>
</Grid>
If i change the collection for <string> to <int> it seems to work fine.. what am i missing?
I’ve run into this as well. Not sure if this is the ideal solution (sure doesn’t seem like it) but this has worked for me