observablecollection

How do I sort an observable collection?

◇◆丶佛笑我妖孽 提交于 2019-12-17 03:54:06
问题 I have a following class : [DataContract] public class Pair<TKey, TValue> : INotifyPropertyChanged, IDisposable { public Pair(TKey key, TValue value) { Key = key; Value = value; } #region Properties [DataMember] public TKey Key { get { return m_key; } set { m_key = value; OnPropertyChanged("Key"); } } [DataMember] public TValue Value { get { return m_value; } set { m_value = value; OnPropertyChanged("Value"); } } #endregion #region Fields private TKey m_key; private TValue m_value; #endregion

How do I update an ObservableCollection via a worker thread?

☆樱花仙子☆ 提交于 2019-12-16 20:13:24
问题 I've got an ObservableCollection<A> a_collection; The collection contains 'n' items. Each item A looks like this: public class A : INotifyPropertyChanged { public ObservableCollection<B> b_subcollection; Thread m_worker; } Basically, it's all wired up to a WPF listview + a details view control which shows the b_subcollection of the selected item in a separate listview (2-way bindings, updates on propertychanged etc.). The problem showed up for me when I started to implement threading. The

UWP/C#: ObservableCollection sort in-place (w/o scrolling)

感情迁移 提交于 2019-12-14 03:54:24
问题 In an UWP app I'm trying to sort an ObservableCollection that is bound to a ListView - therefore collection.OrderBy(..) (which creates a new collection) is not an option. Until now I used this extension-method: public static void Sort<TSource, TKey>(this ObservableCollection<TSource> source, Func<TSource, TKey> keySelector) { List<TSource> sortedList = source.OrderBy(keySelector).ToList(); source.Clear(); foreach (var sortedItem in sortedList) { source.Add(sortedItem); } } Unfortunately this

Shifting nodes up and down in a TreeView

橙三吉。 提交于 2019-12-14 03:13:02
问题 In my program I have a UserControl that contains a TreeView . That TreeView has a ViewModel and a Model relating to it. I would like to make it so that by clicking buttons, I can shift nodes up and down throughout the tree. This is similar to what one might implement on a listBox . As a guide, I am using this article. I am implementing the following functions into the code-behind of the UserControl for which the TreeView exists. //Move up private void moveUp_Click(object sender,

How to update a WPF ComboBox when assigning an object as its SelectedItem?

爱⌒轻易说出口 提交于 2019-12-13 21:12:01
问题 I have a ComboBox which has its ItemsSource bound to an ObservableCollection<CustomObject> where CustomObject has a few properties. Sample class: public class CustomObject : INotifyPropertyChanged { public string Property1 { /*...omitted for brevity...*/ } public string Property2 { /*...omitted for brevity...*/ } public string Property3 { /*...omitted for brevity...*/ } } The SelectedItem property of my ComboBox is bound to a CustomObject property which appears in a DataGrid row. Sample class

Add string array to ObservableCollection<string> does not work

我们两清 提交于 2019-12-13 18:26:39
问题 I try to add strings that are in a string array to an ObservableCollection. The way i do it is: In my constructor i instantiate the collection and add the eventhandler to call my method that adds the strings from the array to the list: public CLoggerViewModel() { this._currenLogContent = new ObservableCollection<string>(); this._memoryAppender.LogContentChanged += new LoggingEventHandler(OnLogContentChanged); } In the eventhandler i want to iterate through the string array and add each string

How to add new ObservableCollection from Icommand command?

冷暖自知 提交于 2019-12-13 17:31:24
问题 I have a simple MVVM project I am learning on. I am trying to add to an ObservableCollection through an ICommand command, but I am unable to? MainWindow.cs I haven't added anything* <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Local="clr-namespace:WpfApplication1" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid.DataContext> <Local:ViewModel></Local:ViewModel

Using Scala's ObservableMap

♀尐吖头ヾ 提交于 2019-12-13 14:13:46
问题 I'm trying to use scala.collection.mutable.ObservableMap. I grabbed the snippet below from scala-user and copied it to the REPL. The email mentions ticket 2704 which has been marked as fixed but this snippet does not work. So has the syntax changed or is subscribe being called incorrectly? This is on 2.9.0.final scala> import scala.collection.mutable._ import scala.collection.mutable._ scala> import scala.collection.script._ import scala.collection.script._ scala> class MyMap extends HashMap

regarding ObservableCollection in c#

此生再无相见时 提交于 2019-12-13 10:45:12
问题 i found a piece of code that use ObservableCollection but they can use list or any other collection related classes. can anyone tell me what is the benifit of using ObservableCollection. ObservableCollection<Employee> empData = new ObservableCollection<Employee> { new Employee{Name="Diptimaya Patra", Contact="0000", EmailID="diptimaya.patra@some.com", Country="India"}, new Employee{Name="Dhananjay Kumar", Contact="00020", EmailID="dhananjay.kumar@some.com", Country="India"}, new Employee{Name

Adding to an observable collection with alternate thread

℡╲_俬逩灬. 提交于 2019-12-13 08:10:21
问题 I am adding to an observablecollection in an alternate thread and this collection is bound to a datagrid from the wpftoolkit. The oncollectionchanged is invoking through the main gui thread when such an event occurs. The problem I am seeing is that most of the time the application will throw: System.ArgumentOutOfRangeException was unhandled Message=Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Source=mscorlib ParamName=index