observablecollection

Sorting ObservableCollection<T>

邮差的信 提交于 2019-12-19 10:32:17
问题 I have Two separate observable Collection where T is a user defined class. These collections are binded to List View and Tree View. I want to show the items of the collections in sorted order. I don't seem to find any sort function on the List and Tree view. Elements in Collections can be removed/added on run time. What is the best way to achieve this? Thanks in advance. Cheers! 回答1: You can implement this behaviour yourself quite easily using the internal Move method by extending the

How to handle a CompositeCollection with CollectionView features?

匆匆过客 提交于 2019-12-19 07:28:31
问题 Is there a way to get notified when CompositeCollection's current location changes? I need to have the CompositeCollection monitored by a CollectionView, any ideas are welcommed. 回答1: You can detect when the current item has changed by monitoring the ICollectionView.CurrentChanged event of your CollectionView. The following code works for me: CompositeCollection cc = new CompositeCollection(); cc.Add(new CollectionContainer { Collection = new string[] { "Oh No!", "Fie" } }); cc.Add(new

How can I make a read-only ObservableCollection property?

只谈情不闲聊 提交于 2019-12-18 18:34:21
问题 I'd like to expose a property on a view model that contains a list of objects (from database). I need this collection to be read-only. That is, I want to prevent Add/Remove, etc. But allow the foreach and indexers to work. My intent is to declare a private field holding the editable collection and reference it with a read-only Public Property. As follows public ObservableCollection<foo> CollectionOfFoo { get { return _CollectionOfFoo; } } However, that syntax just prevents changing the

How to paginate an ObservableCollection?

半腔热情 提交于 2019-12-18 17:04:50
问题 I have a ListBox with way too many items in it and the UI is getting slower and slower (virtualization is on, etc). So I was thinking about displaying only the first 20 items and allow to user to navigate through the result set (i.e. ObservableCollection). Does anybody know if a Pagination mechanism exist for the ObservableCollection? Does anybody has done that before? Thanks! 回答1: This facility is not directly available in the base ObservableCollecton class. You can extend the

Why isn't it possible to update an ObservableCollection from a different thread?

对着背影说爱祢 提交于 2019-12-18 11:34:04
问题 In a multi-threaded WPF application, it is not possible to update an ObservableCollection from a thread other than WPF window thread. I know there are workarounds, so my question is not how to avoid the " This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread " exception. My question is, why there is such an exception? Why wasn't it possible to allow collection updates from any thread? Personally, I don't see any reason

WPF Sorting an ObservableCollection de-selects a ComboBox

拟墨画扇 提交于 2019-12-18 09:39:30
问题 I have a ComboBox where a user can select what JobType they are working on. The ComboBox has a list of AllJobTypes. The problem stems from when a user adds a new JobType, I add the JobType to the AllJobTypes ObservableCollection, then sort it. When the sorting happens the ComboBox get's de-selected and not really sure why. The JobConfig.SelectedJobType.Name never changes in this process. Is there a way to sort an observable collection where it doesn't break the ComboBox? public class

Reverse order of ObservableCollection

混江龙づ霸主 提交于 2019-12-18 09:06:34
问题 I have ObservableCollection that contains a custom object. Normally the items get added at the end of the list What i am looking for: Items being added from the beginning of the list. This may only show in the UI , my entire program is already using the positions of data inside this list. So the objects inside it may not change order in the code behind. This ObservableColection holds Button objects (custom styled). These buttons are being displayed in a ListBox and inside a StackPanel with

XMLSerialize an ObservableCollection

守給你的承諾、 提交于 2019-12-18 08:15:10
问题 I am having a problem in the xml serialization of observable collection. Here is what I am serializing: public enum Status { Pending, Active, Completed, Cancelled } public abstract class Entity : INotifyPropertyChanged { ... } public class UserStory : Entity { public uint StoryID { get; set; } public Status Status { get; set; } ... public ObservableCollection<Task> Tasks { get; set; } } public class Task : Entity { public uint TaskID { get; set; } ... } Here is how I serialize it: public

XMLSerialize an ObservableCollection

爱⌒轻易说出口 提交于 2019-12-18 08:14:36
问题 I am having a problem in the xml serialization of observable collection. Here is what I am serializing: public enum Status { Pending, Active, Completed, Cancelled } public abstract class Entity : INotifyPropertyChanged { ... } public class UserStory : Entity { public uint StoryID { get; set; } public Status Status { get; set; } ... public ObservableCollection<Task> Tasks { get; set; } } public class Task : Entity { public uint TaskID { get; set; } ... } Here is how I serialize it: public

Pause the Updates to DataGrid of bound ObservableCollection<T>

纵然是瞬间 提交于 2019-12-18 06:48:15
问题 Is there a way to pause the NotifyCollectionChanged event of an ObservableCollection ? I thought something like the following: public class PausibleObservableCollection<Message> : ObservableCollection<Message> { public bool IsBindingPaused { get; set; } protected override void OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (!IsBindingPaused) base.OnCollectionChanged(e); } } This pauses the notification indeed, but obviously the then left out (but