inotifycollectionchanged

System.InvalidOperationException 'n' index in collection change event is not valid for collection of size '0'

烈酒焚心 提交于 2019-12-08 10:13:58
问题 I'm getting this exception when triggering a CollectionChanged event on a custom implementation of INotifyCollectionChanged: An exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll but was not handled in user code Additional information: '25' index in collection change event is not valid for collection of size '0'. A XAML Datagrid is bound to the collection as ItemsSource. How can this exception occurrence be avoided? The code follows: public class

EntityFramework EntityCollection Observing CollectionChanged

房东的猫 提交于 2019-12-07 04:03:47
问题 I'm using EntityFramework database first in an application. I would like somehow to be notified of changes to an EntityCollection in my ViewModel. It doesn't directly support INotifyCollectionChanged (why?) and I haven't been successful in finding another solution. Here's my latest attempt, which doesn't work because the ListChanged event doesn't appear to get raised: public class EntityCollectionObserver<T> : ObservableCollection<T>, INotifyCollectionChanged where T : class { public event

EntityFramework EntityCollection Observing CollectionChanged

て烟熏妆下的殇ゞ 提交于 2019-12-05 09:37:56
I'm using EntityFramework database first in an application. I would like somehow to be notified of changes to an EntityCollection in my ViewModel. It doesn't directly support INotifyCollectionChanged (why?) and I haven't been successful in finding another solution. Here's my latest attempt, which doesn't work because the ListChanged event doesn't appear to get raised: public class EntityCollectionObserver<T> : ObservableCollection<T>, INotifyCollectionChanged where T : class { public event NotifyCollectionChangedEventHandler CollectionChanged; public EntityCollectionObserver(EntityCollection<T

Can I rollback collection changes on collection changed event?

橙三吉。 提交于 2019-12-04 19:07:48
问题 I have 2 list views...and add/remove buttons between them. On collection changed event of a list-view-collection in viewmodel, can i rollback the changes for a particular condition ? 回答1: You could handle the CollectionChanged event of the ObservableCollection to backup (via the VM or whatever) the old values (see NotifyCollectionChangedEventArgs.OldItems property) and get them back when needed i.e. when user clicks 'Undo' etc. Update In reference to comments bellow: If you do want to

Can I rollback collection changes on collection changed event?

风流意气都作罢 提交于 2019-12-03 12:41:18
I have 2 list views...and add/remove buttons between them. On collection changed event of a list-view-collection in viewmodel, can i rollback the changes for a particular condition ? You could handle the CollectionChanged event of the ObservableCollection to backup (via the VM or whatever) the old values (see NotifyCollectionChangedEventArgs.OldItems property) and get them back when needed i.e. when user clicks 'Undo' etc. Update In reference to comments bellow: If you do want to rollback the collection from withing the CollectionChanged event-handler, create a flag where you escape the

Observable LinkedList

纵然是瞬间 提交于 2019-12-01 19:32:50
问题 In my WPF app, I have an ItemsControl whose items values are dependant upon the previous item displayed . The ViewModel is an audio file split into parts of variable length, and i need to display it in such manner, with a DateTime displayed on the right, and that's what i need to calculate (I only know each part's length, i need to calculate the actual time it starts and ends, and the position on the ItemsControl). -- ---- ------------ -- -------------------- My first approach was to use an

WPF: How do I hook into a ListView's ItemsSource CollectionChanged notification?

大城市里の小女人 提交于 2019-12-01 19:31:36
I have a ListView that is databound to an ObservableCollection ... <ListView x:Name="List1" ItemsSource="{Binding MyList}" /> I can't seem to find any event that are triggered when the collection changes, so I'm thinking that somehow I need to hook into the collectionchanged notification somehow? I'm not really sure how to do that. Basically, when the collection changes I want to do additional work beyond what the ListView already does in updating it's list. m-y By default the ItemsSource is of type IEnumerable . You need to first cast to a type that has access to the CollectionChanged event,

Observable LinkedList

大憨熊 提交于 2019-12-01 18:33:53
In my WPF app, I have an ItemsControl whose items values are dependant upon the previous item displayed . The ViewModel is an audio file split into parts of variable length, and i need to display it in such manner, with a DateTime displayed on the right, and that's what i need to calculate (I only know each part's length, i need to calculate the actual time it starts and ends, and the position on the ItemsControl). -- ---- ------------ -- -------------------- My first approach was to use an ObservableCollection<MyviewModel> but soon enough some horrors occured : 5-way multibinding in which's

How can I raise a CollectionChanged event on an ObservableCollection, and pass it the changed items?

a 夏天 提交于 2019-11-30 07:59:47
I have a class that inherits from ObservableCollection and adds a few additional methods such as AddRange and RemoveRange My base method call is this: public void AddRange(IEnumerable<T> collection) { foreach (var i in collection) Items.Add(i); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } My problem with this is that I want to access e.NewItems or e.OldItems in the CollectionChanged event to perform an action on whatever item is in the collection, and the NotifyCollectionChangedAction.Reset action does not pass in these values void Instances

How do I update an IValueConverter on CollectionChanged?

时光怂恿深爱的人放手 提交于 2019-11-29 14:40:17
Here's a basic example to explain my problem. Let's say I have ObservableCollection<int> Numbers {get; set;} and an IValueConverter that returns the sum of Numbers. Normally what I'd do is changed the IValueConverter into an IMultiValueConverter and bind a second value to Numbers.Count like this <MultiBinding Converter="{StaticResource SumTheIntegersConverter}"> <Binding Path="Numbers" /> <Binding Path="Numbers.Count" /> </MultiBinding> However I'm unable to use this method to solve my actual problem. It seems like there should be a better way to update the binding when the collection changes