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


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.


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.


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