observablecollection

Observable Collection Notify when property changed in MVVM

橙三吉。 提交于 2019-12-08 16:05:36
问题 I am trying to bind observable collection to DataGrid, i want to notify when any row is edited in datagrid. My code works fine for notifing when record is added or removed but its not notifing when record is edited. Please let me know if this is the right way of binding using observable collection in MVVM and whether i am missing someting. Thanks in advance. public class studentViewModel : INotifyPropertyChanged { #region constructor public studentViewModel() { _student = new studentModel();

Why is the ComboBox losing its SelectedItem when sorting the ItemsSource?

一个人想着一个人 提交于 2019-12-08 13:27:06
问题 Consider this simple example: MainWindow.xaml <Window x:Class="WPF_Sandbox.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" x:Name="ThisControl"> <StackPanel> <ComboBox ItemsSource="{Binding Collection, ElementName=ThisControl}" SelectedItem="a" /> <Button x:Name="SortButton">Sort</Button> </StackPanel> </Window> MainWindow.xaml.cs using System.Collections.Generic; using System.Collections

JSON.NET Line serialization winrt

守給你的承諾、 提交于 2019-12-08 13:04:27
问题 I'm having some trouble with serializing a ObservableCollection of Lines (Shape). I'm developing for Windows RT and I'm using JSON.NET v5.02. I'm getting the following exception for the code below: ObservableCollection<Line> lines; //some code string linesString = JsonConvert.SerializeObjectAsync(lines); // problem An exception of type Newtonsoft.Json.JsonSerializationException occurred in mscorlib.dll but was not handled in user code Additional information: Error getting value from 'X1' on

“Specified argument was out of the range of valid values.Parameter name: index” when adding new item to ObservableCollection<T>

左心房为你撑大大i 提交于 2019-12-08 13:00:04
问题 I get a such exception: 'FooStorageStorage.Add(new TreeViewItem() { Header=i.ToString()})' threw an exception of type 'System.ArgumentOutOfRangeException': "Specified argument was out of the range of valid values.\r\nParameter name: index" I have a property in viewModel: private ObservableCollection<TreeViewItem> fooStorage=new ObservableCollection<TreeViewItem>(); public ObservableCollection<TreeViewItem> FooStorage { get { return facetStorage; } set { facetStorage = value; } } However,

WPF TreeView ObservableCollection notifying sample code

℡╲_俬逩灬. 提交于 2019-12-08 12:25:01
问题 I'm trying to write a C# WPF application and I'm stuck with the TreeView and ObservableCollection. This is my TreeView Items. | Root --- SubItem ------ SubItem | Root --- SubItem ------ SubItem ---------- SubItem I'm modifyng this items from other window and I need to update this treeview without re-loading all items. I've made my search and I found ObservableCollection. But I can't understand how to use ObservableCollection and notify changes and update this list. Can you give me some sample

INotifyPropertyChanged event not firing when Observable Collection changed in WPF in VB.NET

眉间皱痕 提交于 2019-12-08 09:25:51
问题 I'm trying to use databinding in WPF with an MVVM pattern. So far, it seems that everything is plumbed up properly and I'm using the right type of classes and objects. My observable collection loads to first time correctly, but won't refresh on the datagrid when it changes. Observable Collections should automatically implement INPC and I've also provided a handler for it in my base class, so I'm confused why it is still not working and updating my UI. Here's my code below: ViewModelBase Class

WPF datagrid cannot add a row after binding to collection with data

喜夏-厌秋 提交于 2019-12-08 09:16:47
问题 I have a wpf applicatiion with multiple datagrids, all bound to seperate ObservableCollections of custom objects. When the collections are empty, i see a blank row and I can add data. However, when I add objects to the collections programmatically (read from XML), ONE of the datagrids does not show a blank row and does not allow me to add data, while the others do. I have checked the cunstructors of all objects to be public, and I refresh all datagrids programmatically after I add objects the

How to write an observable collection to a txt file?

一曲冷凌霜 提交于 2019-12-08 07:51:24
Whats the best way to write an observable collection to a txt file? I currently have the following public ObservableCollection<Account> SavedActionList = new ObservableCollection<Account>(); using (System.IO.StreamWriter file = new System.IO.StreamWriter("SavedAccounts.txt")) { foreach (Account item in SavedActionList) { file.WriteLine(item.ToString()); //doesn't work } file.Close(); } I'm not sure why it won't write to the file. Any ideas? You can easily just write: File.WriteAllLines("SavedAccounts.txt", SavedActionList.Select(item => item.ToString())); However, this will require your

Add object to ObservableCollection List object

不羁岁月 提交于 2019-12-08 05:45:31
问题 How to add one object to ObservableCollection list object? I have class called "Assest" and I have created ObservableCollection list of Asset and I want to maintain it like adding and deleting element from that ObservableCollection list. Now I'm getting error when I try to add single element to ObservableCollection. Here's my code. private static ObservableCollection<Assest> _collection = null; public ObservableCollection<Assest> AssestList { get { if (_collection == null) { _collection = new

Why can't I add attributes when serializing ObservableCollection<T>?

你。 提交于 2019-12-08 05:25:11
问题 I'm trying to extend an ObservableCollection with a few custom properties and have it serialize. However, I can't seem to get it to serialize these properties. I'm using .NET 4.0 where they fixed the serialization issues of ObservableCollection, but am still having problems. My hunch is that GetObjectData is being called on the base class and not mine. Any ideas? [Serializable] [XmlRoot(ElementName = "MyCollection")] public class MyCollection : ObservableCollection<MyItem>, ISerializable {