observablecollection

Create a generic collection of derived interfaces from a collection of base interfaces

孤街浪徒 提交于 2021-02-11 18:12:25
问题 I have a base interface public interface IBase { ... } and a interface that derives from this base public interface IChild : IBase { ... } Within my code, I call a method which will return me a List<IBase> (legacy code). With this List I am trying to fill a ObservableCollection<IChild> : List<IBase> baseList= GetListofBase(); ChildList = new ObservableCollection<IChild>(); // how to fill ChildList with the contents of baseList here? I know it is not possible to cast from a base to a derived

Create a generic collection of derived interfaces from a collection of base interfaces

一曲冷凌霜 提交于 2021-02-11 18:05:29
问题 I have a base interface public interface IBase { ... } and a interface that derives from this base public interface IChild : IBase { ... } Within my code, I call a method which will return me a List<IBase> (legacy code). With this List I am trying to fill a ObservableCollection<IChild> : List<IBase> baseList= GetListofBase(); ChildList = new ObservableCollection<IChild>(); // how to fill ChildList with the contents of baseList here? I know it is not possible to cast from a base to a derived

Using ObservableCollection across UI and Non-UI threads

我是研究僧i 提交于 2021-02-11 13:38:57
问题 I am using the SortableObservableCollection described here. Now I'd like to manipulate it from a UI or a non-UI thread so I tried the solution described here: using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Runtime; using System.Windows.Data; public class SortableObservableCollection<T> : ObservableCollection<T> { private object _itemsLock = new object(); public SortableObservableCollection() : base() { BindingOperations

How to bind collection dependency property in UserControl

回眸只為那壹抹淺笑 提交于 2021-02-10 12:31:10
问题 This is not a duplicate! When I failed I tried to look to similar posts but without success. I cannot understand why OnUCItemsSourceChanged is not called? I'm pretty sure that I miss something simple but I cannot find it. I have Window that contains UserControl1 which has attached collection property that is bound to Window 's WindowCollection collection. I expect UserControl1.OnUCItemsSourceChanged to be called when I add items to WindowCollection . But it doesn't happen. What I miss?

Update item in ObservableCollection as Thread safe

点点圈 提交于 2021-02-08 12:15:29
问题 Is there any good way to update a Item in ObservableCollection as "Thread safe" ? Here is my way. var target = MyCollection.Where(i => i.Key== a_Key).Single(); MyCollection[MyCollection.IndexOf(target)] = NewValue; But I worry. If I use Index, It may not thread safe.. Please advice me. In internet, THere is some thread-safe-ObservableCollection. I want to use No.1. Is there any better way ? https://gist.github.com/thomaslevesque/10023516 https://www.codeproject.com/Articles/64936

How to call a public event from a static function in the same class?

守給你的承諾、 提交于 2021-02-07 17:31:28
问题 I have a class that contains an ObservableCollection of another class. I want to be notified if one of the class members is changed, because I need to do some calculating in the MediaCollection class. So I added an event to that class: public event PropertyChangedEventHandler PropertyChangedEvent; which is called in this collection class: public class MediaCollection : INotifyPropertyChanged { private List<MediaEntry> ModifiedItems = new List<MediaEntry>(); private ObservableCollection

how to split ObservableCollection

放肆的年华 提交于 2021-02-05 08:15:59
问题 i have ObservableCollection with 100 records. now i want to get split that collection in 10 new collection each having 10 records. it means 1 collection = 100 records (10 collection = 10 records) = 1 collection any help will be apricited. 回答1: Using Linq var collection=new ObservableCollection<int>(Enumerable.Range(1,100)); collection.Aggregate(new ObservableCollection<ObservableCollection<int>>(), (x,i)=>{ if (!x.Any() || x.Last().Count()==10) x.Add(new ObservableCollection<int>()); x.Last()

Get compiler generated delegate for an event

别来无恙 提交于 2021-01-28 14:49:48
问题 I need to know what handlers are subsribed to the CollectionChanged event of the ObservableCollection class. The only solution I found would be to use Delegate.GetInvocationList() on the delegate of the event. The problem is, I can't get Reflection to find the compiler generated delegate. AFAIK the delegate has the same name as the event. I used the following piece of code: PropertyInfo notifyCollectionChangedDelegate = collection.GetType().GetProperty("CollectionChanged", BindingFlags