source: extensions/PiwigoLib/PiwigoWpf/DTO/AsyncObservableCollection.cs @ 11935

Last change on this file since 11935 was 11935, checked in by bayral, 13 years ago

root category handled

File size: 2.1 KB
Line 
1using System.Collections.Generic;
2using System.Collections.ObjectModel;
3using System.Threading;
4using System.Collections.Specialized;
5using System.ComponentModel;
6
7namespace Com.Piwigo.Wpf.DTO
8{
9    public class AsyncObservableCollection<T> : ObservableCollection<T>
10    {       
11
12        public AsyncObservableCollection()
13        {
14        }
15
16        public AsyncObservableCollection(IEnumerable<T> list)
17            : base(list)
18        {
19        }
20
21        protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
22        {
23            if (SynchronizationContext.Current == PwgModelManager.WPF_SynchronizationContext)
24            {
25                // Execute the CollectionChanged event on the current thread
26                RaiseCollectionChanged(e);
27            }
28            else
29            {
30                // Send the CollectionChanged event on the creator thread
31                PwgModelManager.WPF_SynchronizationContext.Send(RaiseCollectionChanged, e);
32            }
33        }
34
35        private void RaiseCollectionChanged(object param)
36        {
37            // We are in the creator thread, call the base implementation directly
38            base.OnCollectionChanged((NotifyCollectionChangedEventArgs)param);
39        }
40
41        protected override void OnPropertyChanged(PropertyChangedEventArgs e)
42        {
43            if (SynchronizationContext.Current == PwgModelManager.WPF_SynchronizationContext)
44            {
45                // Execute the PropertyChanged event on the current thread
46                RaisePropertyChanged(e);
47            }
48            else
49            {
50                // Send the PropertyChanged event on the creator thread
51                PwgModelManager.WPF_SynchronizationContext.Send(RaisePropertyChanged, e);
52            }
53        }
54
55        private void RaisePropertyChanged(object param)
56        {
57            // We are in the creator thread, call the base implementation directly
58            base.OnPropertyChanged((PropertyChangedEventArgs)param);
59        }
60    }
61}
Note: See TracBrowser for help on using the repository browser.