Reputation: 12745
When we have a twoway binding involved between View and View-Model, we implement the INotifyPropertyChanged interface which has the following event:
// Summary:
// Occurs when a property value changes.
event PropertyChangedEventHandler PropertyChanged;
But can I do the same without implementing INotifyPropertyChanged?
Upvotes: 2
Views: 406
Reputation: 35870
If you can't implement INotifyPropertyChanged
(INPC) (or don't have the source to what you want to bind to) then you should wrap whatever it is you want to bind to in your View Model and the View Model would implement INPC for the binding and have to to get/set data to, presumably, that other class.
Upvotes: 2
Reputation: 11051
You can of course. You simply loose the easy way to update the view when the viewmodel is changed. Now there are ways to overcome that.
DataContext
, that way all bindings gets evaluated
again, but this is very expensive. But obviously these are all very strange workarounds. Its also worth mentioning, that binding to an object that doesn't implement INotifyPropertyChanged is usually slower.
Upvotes: 1
Reputation: 22445
i would say no. you have to implement INotifyPropertyChanged in any way, otherwise binding with twoway would not work.
Upvotes: 0
Reputation:
If you want to avoid implementing INotifyPropertyChanged
explicitly, you could use a code-weaving tool like PostSharp. Then, implementing INotifyPropertyChanged
becomes as simple as
[NotifyPropertyChanged]
public class Shape
{
public double X { get; set; }
public double Y { get; set; }
}
You can find more details here: http://www.sharpcrafters.com/solutions/notifypropertychanged# .
Upvotes: 1