WPF ViewModel not active presenter

北城以北 提交于 2019-12-11 20:43:19

问题


There is a ViewModel that consists of some related object (nodes and lines( , How it can be possible to display (synchronize) these VM in View and keep object connections. I use some DataTemplate to map model to view but each object would be synchronized (with powerful binding) to its related object but how can i link (and synchronize) this DataTemplate generated UI element together. I describe problem from another viewpoint here: Sunchronizing view model and view


回答1:


To keep your view synchronized you should use bindings, your binding sources need to implement certain interfaces or be dependency properties though. For collections you need to implement INotifyCollectionChanged and for properties you'd use INotifyPropertyChanged, if you then change the source your view will change as well.




回答2:


Next to implementing INotifyPropertyChanged and using ICollectionChanged (ObservableCollection) and binding to the views, you might consider implementing IEditableObject when you want to support the editing of the data.

This interface allows you to undo edit actions. Without implementing IEditableObject you would need to go back to the data source to reset the to the original values when canceling the modifications. The interface is also supported by the DataGrid.




回答3:


You can synchronize the VM and View using Relaying Command Logic.

you can see a sample workout here

Binding the "WindowState" property of a window in WPF using MVVM



来源:https://stackoverflow.com/questions/4698655/wpf-viewmodel-not-active-presenter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!