I have an ObservableCollection defined as follows
private ObservableCollection<RelayConfig> _relayConfigs;
public ObservableCollection<RelayConfig> RelayConfigs {
get {return _relayConfigs;}
set { _relayConfigs = value; }
}
This is bound to wpf Datagrid using ItemsSource attribute and populated as given below
RelayConfigs = new ObservableCollection<RelayConfig>(unitOfWork.RelayConfigRepository.GetQueryable().Include(rc => rc.StandardContacts));
I am removing items from ObservableCollection that matches a specific criteria like this.
RelayConfigs.RemoveWhere(r => r.IsMarked);
RemoveWhere is an Extension method for ObservableCollection, defined like this
public static void RemoveWhere<T>(this ICollection<T> collection, Func<T, bool> predicate) {
var i = collection.Count;
while (i-- > 0) {
var element = collection.ElementAt(i);
if (predicate(element)) {
collection.Remove(element);
}
}
}
The issue is that when I remove some rows from the ObservableCollection using the above setup, I don't see the DataGrid getting refreshed. The rows still linger around in the DataGrid, when infact it does not exist in the ObservableCollection. Any ideas why Datagrid does not get refreshed.