更新可观察集合
我目前正在开发一个使用 MVVM 的应用程序,该应用程序需要在组合框中显示一些数据。它们绑定到 ObservableCollections。数据存储在数据表中。
我有许多对象,例如名称和位置。每个组合框包含名称或位置。姓名列表旁边有一个数字,显示有多少人被称为该名字。位置确实相似。现在,当用户单击某个名称时,位置框中的数字会发生变化,以显示该位置上居住着该名称的人数。名称和位置对象完全独立,彼此一无所知。如果用户随后单击某个位置,则会更新名称组合框。原始数据包含在带有名称和位置列的数据表中。 (最终项目中大约有7个组合框,数据表也会相应增加)。是否只是再次查询数据表并清除组合框中的对象并将其替换为新数据?
抱歉冗长的消息。
I'm currently working on an app using MVVM that needs to have some data displayed in comboboxes. These are bound to ObservableCollections. The data is stored within a datatable.
I have a number of objects such as, for example, name and location. Each combobox contains either name or location. The list of names have a number next to them showing how many people are called that name. The location does similar. Now when the user clicks on a name, the numbers in the location box change to show how many people of that name live in the locations. The name and location objects are completely seperate and know nothing of each other. If the user then clicks on a location, then this would update the name combobox. The raw data is contained in a datatable with name and location column. (There will be approximately 7 comboboxes in the final project, and the dattable will increase accordingly). Is it a case of just querying the datatable again and clearing and replacing the objects in the combobox with the new data?
Sorry for the long winded message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果列表发生完全更改,
ObservableCollection
对您几乎没有帮助。您可能会发现更容易让组合框具有 ViewModel 上的ItemsSource
属性,这些属性返回IEnumerable
并在选择特定项目框(设置SelectedItem
)。In case of complete changes of the lists, the
ObservableCollection
does little to help you. You might find it easier to have the combo boxes haveItemsSource
to properties on the ViewModel which return anIEnumerable<T>
and callPropertyChanged
when a particular item box is selected (SelectedItem
is set).