MVVM Property databinding
Why do most MVVM databinding properties examples check to see if the current value is equal to previous.开发者_Go百科
private string name;
public string Name
{
set
{
if(this.name != value) <- why is this check needed.
{...}
}
}
thanks!
In MVVM a property setter triggers the UI update following a property change. Adding this check prevents the UI to refresh (and possibly flicker) unnecessarily.
In the case of a Binding "TwoWay", When changing the value in the XAML, the value in the bound property in the ViewModel side must not re-send the same value. On the other hand if the value (ViewModel bind side) is not changed it is not necessary to throw the "RaiseChangedProperty" event to the View.
精彩评论