observablecollection

Why ObservableCollection does not have a RemoveAll method?

最后都变了- 提交于 2020-06-25 07:50:26
问题 Why ObservableCollection doesn't has the RemoveAll method like a List ? I have implemented an extension method to provide this functionality to the ObservableCollection , but I would like to understand if there is a specific reason for not providing this functionality. Would it possibly effect Data Binding in some way due to Collection change ? This post does specify a few things that could go wrong while using ObservableCollections , but does not address this question. 回答1: It does have a

Binding to first N items in an ObservableCollection on a ListView

不羁岁月 提交于 2020-05-31 05:54:53
问题 I have an ObservableCollection<T> in my application that can hold numerous items. Specifically, this is summary information from a potentially extensive logger. What I'd like to do is bind strictly the top 3 items of this collection to WPF ListView . Is there XAML syntax, or a simple enough way to create a secondary property in my VM, to always return the top 3 items in the collection as well as update any changes to the collection as a normal ObservableCollection<T> would if you were

Sort ObservableCollection<string> through C#

被刻印的时光 ゝ 提交于 2020-01-26 09:44:11
问题 I have below ObservableCollection<string> . I need to sort this alphabetically. private ObservableCollection<string> _animals = new ObservableCollection<string> { "Cat", "Dog", "Bear", "Lion", "Mouse", "Horse", "Rat", "Elephant", "Kangaroo", "Lizard", "Snake", "Frog", "Fish", "Butterfly", "Human", "Cow", "Bumble Bee" }; I tried _animals.OrderByDescending . But I don't know how to use it correctly. _animals.OrderByDescending(a => a.<what_is_here_?>); How can I do this? 回答1: Introduction

Sort ObservableCollection<string> through C#

为君一笑 提交于 2020-01-26 09:43:30
问题 I have below ObservableCollection<string> . I need to sort this alphabetically. private ObservableCollection<string> _animals = new ObservableCollection<string> { "Cat", "Dog", "Bear", "Lion", "Mouse", "Horse", "Rat", "Elephant", "Kangaroo", "Lizard", "Snake", "Frog", "Fish", "Butterfly", "Human", "Cow", "Bumble Bee" }; I tried _animals.OrderByDescending . But I don't know how to use it correctly. _animals.OrderByDescending(a => a.<what_is_here_?>); How can I do this? 回答1: Introduction

Implement OnCollectionChanged so that ListBox updates automatically WPF

白昼怎懂夜的黑 提交于 2020-01-25 17:33:50
问题 I have this object wrapper, whose instances I populate the collection with: public class Multimedia : INotifyPropertyChanged { //... constructor //... getters and setters for the properties public void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { ObservableCollection<Multimedia> objSender = sender as ObservableCollection<Multimedia>; NotifyCollectionChangedAction action = e.Action; } } The collection: public class MultiMediaList : ObservableCollection<Multimedia> {

WPF Converters and ObservableCollections

旧街凉风 提交于 2020-01-24 09:45:11
问题 I'm binding an ObservableCollection to a control which has a converter to change its visibility depending on if the collection has any values or not: Simplified example: XAML: <Window.Resources> <local:MyConverter x:Key="converter"/> </Window.Resources> <Grid x:Name="grid"> <Rectangle Height="100" Width="200" Fill="CornflowerBlue" Visibility="{Binding Converter={StaticResource converter}}"/> <Button Content="click" HorizontalAlignment="Left" VerticalAlignment="Top" Click="Button_Click"/> <

ObservableCollection CollectionChanged not helpful in WPF MVVM

空扰寡人 提交于 2020-01-24 08:59:06
问题 I am using a DataGrid and is bind using an ObservableCollection in the ViewModel private ObservableCollection<StockItem> _stockList; public ObservableCollection<StockItem> StockList { get { return _stockList; } set { _stockList = value; OnPropertyChanged("StockList"); } } The StockItem class contains its Properties which are the Column in DataGrid. There is a column named Amount in DataGrid whose values changed with Quantity*Price Column of the same datagrid. I have a Property called