observablecollection

Bind SelectedItem in a ListBox to CommandParameter in a ContextMenu

别等时光非礼了梦想. 提交于 2019-12-11 18:26:05
问题 Although this question is very similar to others posted, it has a few twist! I have an ObservableCollection of items in a ListBox and use a DataTemplate to display some of the collection members. However, I have a ContextMenu defined so I can execute DelegateCommands defined in my ViewModel using the Command parameter. All my Bindings are working up to here, except that I need to provide an argument for the Command in the ViewModel using CommandParameter of the item selected in the ListBox so

TreeView and databinding failed

岁酱吖の 提交于 2019-12-11 16:45:13
问题 I am working around the MVVM pattern and a TreeView. I failed to bind the data models with the view. Here's my currently code: MainWindow.xaml: xmlns:reptile="clr-namespace:Terrario.Models.Reptile" ... <TreeView x:Name="TrvFamily" Grid.Row="1" Grid.Column="0" ItemsSource="{Binding }"> <TreeView.ItemTemplate> <HierarchicalDataTemplate DataType="{x:Type reptile:Family}" ItemsSource="{Binding Items}"> <TextBlock Text="{Binding Name}" /> </HierarchicalDataTemplate> </TreeView.ItemTemplate> <

Binding TabControl to ObservableCollection With Different Content

爷,独闯天下 提交于 2019-12-11 15:02:27
问题 'm trying to create w mainwindow that will have a tabcontrol containing multiple items ( each one is shown only on demand )... let's say we have item of type A, item of type B and item of type C I want ( using MVVM pattern) to have an observablecollection of objects that represent my tabitems and that are related to my userscontrols ( each tabitem is a usercontrol)... The problem is that i didn't figure out how to do it. i've a tabItemViewModelBase class : public class TabItemViewModelBase :

How to create a race track scoreboard in WPF

血红的双手。 提交于 2019-12-11 14:59:43
问题 Im trying to develop a race track scoreboard like this: The problem is that I dont know which is the best practice to do it. Actually I tryied to create an Observable Collection that is updated constantly. Well, the problem is that when I try to sort the scoreboard dinamically by drivers best lap, the drivers position is always static. I used a CollectionViewSource combined with a ListBox for sort the drivers by the Property "BestLap" but It seems that the drivers position is sorted only when

sort and group Icollectionview in WPF

被刻印的时光 ゝ 提交于 2019-12-11 13:17:49
问题 I have created a listview control in WPF and has success fully bound Icollectionview object of ObservableCollection<object> . My listview columns are created dynamically. I have to sort and group my listview and it is not working properly. My code is as below. private void LaodList() { dt = new DataTable(); dt.Columns.Add("AA", typeof(string)); dt.Columns.Add("BB", typeof(string)); dt.Columns.Add("cc", typeof(string)); dt.Rows.Add("12", "66",11); dt.Rows.Add("33", "44",22); dt.AcceptChanges()

How to bind an observable collection to Multiple user controls at runtime?

狂风中的少年 提交于 2019-12-11 12:24:33
问题 I am stucked at the part where I have to bind a collection to a dynamic usercontrol. Scenario is something like this. I have a dynamic control, having a expander , datagrid, combobox and textbox, where combox and textbox are inside datagrid. There are already two collections with them. One is binded with combobox and another is binded with datagrid. When the item is changes in combox its respective value is set to its respective textbox, and so on. and this pair of value is then set to the

What triggers UI to update when ItemsControl.ItemsSource changed?

徘徊边缘 提交于 2019-12-11 12:05:23
问题 I was just looking into the difference between BindingList and ObservableCollection following this question: Why NOT BindingList in WPF As part of this, I tested binding the ItemsSource of an ItemsControl to various types, including List, Collection, ObservableCollection and BindingList. What surprised me is that the interface updated when either the ObservableCollection or the BindingList were modified, but not when the others were. So what is WPF listening to that causes that update? It can

How to correctly handle the CollectionChanged event of datagrid?

扶醉桌前 提交于 2019-12-11 10:38:34
问题 I initially asked a question related to dataGrid insert/delete/save operations with Entity Framework here However I was not able to totally get the suggested approach to work. Here's my approach so far: ViewModel constructor public DeviceDatabaseViewModel() { LoadData(); } LoadData private void LoadData() { _context.Devices.Load(); _devices = _context.Devices.GetLocal(); _devices.CollectionChanged += Device_CollectionChanged; DeviceCollectionView = (CollectionView)new CollectionViewSource {

Subscribing to CollectionChanged event with ObservableCollection

左心房为你撑大大i 提交于 2019-12-11 09:56:15
问题 When I create an ObservableCollection , how to run additional logic when items added or removed? Public Property Employees As ObservableCollection(Of employee) Get If _employees Is Nothing Then _employees = New ObservableCollection(Of employee) AddHandler _employees.CollectionChanged, AddressOf OnEmployeesChanged End If Return _employees End Get Set(ByVal value As ObservableCollection(Of employee)) _employees = value End Set End Property Private _employees As ObservableCollection(Of employee)

C# : public observablecollection<ViewModel> instance pass items to protected observablecollection<ViewModel>

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 09:52:04
问题 I have the following class which work just fine public class RemoteSource { ObservableCollection<RemoteDataViewModel> remote; string[] _servers = new string[] { "server", "server", "server", "server", "server" }; public RemoteSource() { remote = CreateDataSource(); } protected ObservableCollection<RemoteDataViewModel> CreateDataSource() { ObservableCollection<RemoteDataViewModel> res = new ObservableCollection<RemoteDataViewModel>(); ITerminalServicesManager _manager = new