observablecollection

When observablelist generate update change event?

耗尽温柔 提交于 2019-12-22 05:52:34
问题 I tried different collections under different conditions but all changes that I was able to receive were Permutation, Add, Removed and Replace changes. In what conditions does update change emerge? What base class, what stored class and what operations is needed to produce such event? 回答1: To generate an update event, you must create an ObservableList with an extractor. The extractor is a function mapping each element in the list to an array of Observable s. If any of those Observable s

WPF List of ViewModels bound to list of Model objects

北战南征 提交于 2019-12-21 22:26:11
问题 In the model, I have: public ObservableCollection<Item> Items { get; private set; } In the ViewModel, I have a corresponding list of ItemViewModels. I would like this list to be two-way bound to the model's list: public ObservableCollection<ItemViewModel> ItemViewModels ... In the XAML, I will bind (in this case a TreeView) to the ItemViewModels property. My question is, what goes in the "..." in the ViewModel shown above? I am hoping for a line or two of code to binds these two

.NET 4.0 Indexer with ObservableCollection

丶灬走出姿态 提交于 2019-12-21 06:42:15
问题 What is the .NET C# syntax for an ObservableCollection with an indexer? I would like an ObservableColletion and refer to the items by ordinal position or a string name. I know you the use this to denote an indexer but I don't know how to put that in an ObservableCollection. Thanks Thanks for the 4 answers. I know how create and ObservableCollection and I know how to create an indexer. I don't know how to combine them. I am asking for sample code for an ObservableCollection with an ordinal and

.NET 4.0 Indexer with ObservableCollection

别说谁变了你拦得住时间么 提交于 2019-12-21 06:41:09
问题 What is the .NET C# syntax for an ObservableCollection with an indexer? I would like an ObservableColletion and refer to the items by ordinal position or a string name. I know you the use this to denote an indexer but I don't know how to put that in an ObservableCollection. Thanks Thanks for the 4 answers. I know how create and ObservableCollection and I know how to create an indexer. I don't know how to combine them. I am asking for sample code for an ObservableCollection with an ordinal and

ObservableCollection in the service layer of the WPF MVVM application

给你一囗甜甜゛ 提交于 2019-12-21 04:26:05
问题 Examples of WPF MVVM apps I've seen on the Internet consider VM a layer which interacts with a service layer which either uses "old" events from an external library, or interacts with web using HTTP or whatever. But what if I build all M, V, VM, service and other parts myself? How to properly build interaction between the service layer and the viewmodel layer? Can I just put ObservableCollection<OrderModel> into the service and return it as is from the viewmodel for the view, or is it

WPF - How can I implement an ObservableCollection<K,T> with a key (like a Dictionary)?

邮差的信 提交于 2019-12-21 04:22:14
问题 I have used an ObservableCollection with WPF for binding and this works well. What I really want at the moment is a Dictionary like one, that has a key that I can use, so effectively like "ObservableCollection". Can you suggest the code that could be used to provide such an ObservableCollection? The goal is to have a Dictionary like structure that I can bind to from WPF. Thanks 回答1: Someone already made it. I haven't try it yet but nothing to lose. 回答2: Create a class that implements the

Should my ViewModel have an ObservableCollection of Views or ViewModels?

。_饼干妹妹 提交于 2019-12-20 12:35:15
问题 I'm trying to understand the basic MVVM design approach when using ItemsControl by binding it via DataTemplates to ObservableCollections on the ViewModel. I've seen examples that bind to ObservableCollections of strings , Views , and ViewModels . Binding to strings seems to be only for demos , it is the binding to " ViewModels that contain collections of Views that contain collections of ViewModels " that the power of WPF seems to really come out. For those of use proficient in the MVVM

Can one bind a combobox Itemssource from a datatemplate of a ItemsControl

限于喜欢 提交于 2019-12-20 05:31:59
问题 Given ComboBox in the ItemsControl will have different items which is based on the DataContext of the item (not of the ItemsControl ). Can it be done? And how? Preferably from code behind. I have the following DataModel : class Tester { public Tester(string name, string surname) { Name = name; Surname = surname; } public string Name { get; set; } public string Surname { get; set; } public override string ToString() { return Name + " " + Surname; } } class TheT { public ObservableCollection

WPF: How do I hook into a ListView's ItemsSource CollectionChanged notification?

╄→尐↘猪︶ㄣ 提交于 2019-12-20 01:06:44
问题 I have a ListView that is databound to an ObservableCollection ... <ListView x:Name="List1" ItemsSource="{Binding MyList}" /> I can't seem to find any event that are triggered when the collection changes, so I'm thinking that somehow I need to hook into the collectionchanged notification somehow? I'm not really sure how to do that. Basically, when the collection changes I want to do additional work beyond what the ListView already does in updating it's list. 回答1: By default the ItemsSource is

How can i cast into a ObservableCollection<object>

醉酒当歌 提交于 2019-12-19 13:46:15
问题 How can i cast from ObservableCollection<TabItem> into ObservableCollection<object> this doesnt work for me (ObservableCollection<object>)myTabItemObservableCollection 回答1: you should copy like this return new ObservableCollection<object>(myTabItemObservableCollection); 回答2: Basically, you can't. Not now, and not in .NET 4.0. What is the context here? What do you need? LINQ has Cast<T> which can get you the data as a sequence , or there are some tricks with generic methods (i.e. Foo<T>