在视图之间更新 [英] Updating between Views
问题描述
我有一个"Main_View"显示由EmployeesList绑定的Datagrid中的所有员工
I have a "Main_View" that display all the Employees in a Datagrid bindded by the EmployeesList
示例:
ID:1名称:Arelly
ID:1 Name:Arelly
ID:2姓名:Airam
ID:2 Name:Airam
ID:3名称:Alison
ID:3 Name:Alison
我有一个显示新的按钮[新员工] "窗口"我的Main_View请求ID和NAME字段,但不知道如何更新Main_ViewModel中的EmployeeList
i have a button [New Employee] that display a new "Window" out of my Main_View that ask for ID and NAME field but don't know how to update the EmployeeList in the Main_ViewModel
当然,使用其他方法可能会更容易 但我想要保持添加员工在一个单独的窗口和员工列表中的独立窗口
Of course this could be easier using other approaches but I want to keep the Add Employee in a separated window and the list of employees in an independently Window
推荐答案
那你应该有一个ViewModel任何需要它的UI元素都可以访问。 Employees的集合应该是一个ObservableCollection(of ....)。 这将确保对集合的任何更改(如添加)都将反映在
UI中。
Well you should have a ViewModel that any UI elements that need it can access. The collection of Employees should be an ObservableCollection (of ....). This will ensure that any changes (like an add) to the collection will be reflected in the UI.
这篇关于在视图之间更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!