observablecollection

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

帅比萌擦擦* 提交于 2019-12-08 04:49:27
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 collections. All datagrid have the property CanUserAddRows set to true. Has anybody have an idea what

WPF: Accessing bound ObservableCollection fails althouth Dispatcher.BeginInvoke is used

[亡魂溺海] 提交于 2019-12-08 02:01:58
问题 I have the following: public ICollectionView Children { get { // Determining if the object has children may be time-consuming because of network timeouts. // Put that in a separate thread and only show the expander (+ sign) if and when children were found ThreadPool.QueueUserWorkItem(delegate { if (_objectBase.HasChildren) { // We cannot add to a bound variable in a non-UI thread. Queue the add operation up in the UI dispatcher. // Only add if count is (still!) zero. Application.Current

WPF - Combobox - Add Item when user enter text in combo

和自甴很熟 提交于 2019-12-08 01:57:23
问题 I have a ComboBox binded with an ObservableCollection . How can I do when user enter a text in the ComboBox , if item not in the list, the code automatically add a new item to the list? <ComboBox Name="cbTypePLC" Height="22" ItemsSource="{StaticResource TypePLCList}" SelectedItem="{Binding TypePLC}" IsReadOnly="False" IsEditable="True"> </ComboBox> 回答1: Bind Text property of your combo box to your view model item and then add to the bound collection there, like, Text="{Binding UserEnteredItem

Trigger InotifyPropertyChanged/CollectionChanged on ObservableCollection

丶灬走出姿态 提交于 2019-12-08 01:45:20
问题 I've tried looking at other topics on this but I haven't found a working implementation to my question. Basically, I have an ObservableCollection called "FruitBasket" that contains different kinds of fruit. FruitBasket itself contains ObservableCollections for each respective type of fruit that passes through so that they can be used as ItemSources for ListViews (Denoted by their names "AppleContainer" and "OrangeContainer"), each displaying one kind of fruit. Because the fruit classes

Xamarin ListView bound to ObservableCollection changing at random

故事扮演 提交于 2019-12-07 23:16:58
问题 Please consider the following issue: I have a Xamarin Forms project, using ViewModels and XAML binding. I have a particular ListView that is bound to an ObservableCollection of a particular object. The objects contain all the required information to display the following list of buttons: <ListView ItemsSource="{Binding ListViewItems}" Margin="0,20,0,0" RowHeight="130" SeparatorVisibility="None" VerticalOptions="FillAndExpand" Grid.Column="1" Grid.Row ="0" > <ListView.ItemTemplate>

WPF Listbox binding

谁说胖子不能爱 提交于 2019-12-07 11:13:10
问题 I have a physician object, and one of its properties is an ObservableList of clinics. It is being used in a window to show the details of a physician. I can get individual properties to bind to TextBox and ComboBox controls, but I can't get the list of clinics to bind to my ListBox . Here is the xaml for my ListBox : <ListBox Height="318" HorizontalAlignment="Left" Margin="422,0,0,0" Name="lbClinic" VerticalAlignment="Top" Width="158" SelectedValue="{Binding ClinicID, Path=Clinics, Mode

C# ObservableCollection OnCollectionChanged not firing when item changes

亡梦爱人 提交于 2019-12-07 10:08:30
问题 From the MSDN about OnCollectionChanged: "Occurs when an item is added, removed, changed, moved, or the entire list is refreshed." I'm changing a property attached to an obj that resides in my collection, but OnCollectionChanged isn't fired. I am implementing iNotifyPropertyChanged on the obj class. public class ObservableBatchCollection : ObservableCollection<BatchData> { protected override void OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if(e

Best performance for ObservableCollection.AddRange

大兔子大兔子 提交于 2019-12-07 08:37:11
问题 I'm writing an extension method for ObservableCollection and have read that the .Add function raises 3 property changed events per call, So that something like this is a bad idea: public static void AddRange<T>(this ObservableCollection<T> oc, IEnumerable<T> collection) { if (collection == null) { throw new ArgumentNullException("collection"); } foreach (var i in collection) { oc.Add(i); } } Are there any other solutions to this? 回答1: Given that Concat<T> is an extension method it is almost

How can I refresh a combobox after modifying its ItemsSource ObservableCollection

蹲街弑〆低调 提交于 2019-12-07 01:25:00
问题 The problems is simple: when ItemsSource is updated Combobox doesn't "refresh" e.g. new items don't appear to be added to the list of items in the combobox. I've tried the solution from aceepted answer to this question: WPF - Auto refresh combobox content with no luck. here's my code, XAML: <ComboBox Name="LeadTypeComboBox" ItemsSource="{Binding LeadTypeCollection}" /> ViewModel: public ObservableCollection<XmlNode> LeadTypeCollection { get; set; } the way I update this collection is in the

WPF Grouping with a Collection using MVVM

烈酒焚心 提交于 2019-12-06 21:40:59
问题 I am new to both WPF and MVVM so I will beg forgiveness upfront if this is a silly question. Problem: I am trying to create a grouped list of items using the MVVM design pattern. I can do it with code behind, but would prefer a more elegant solution. Details Let's say I have a collection of animals: horse, wolf, monkey, tiger, polar bear, zebra, bat, etc. These animals are grouped by continents: North America, Africa, Antarctica, etc. Goal: Within a wrap panel, I would like to create grouped