开发者

MVVM Property databinding

开发者 https://www.devze.com 2023-01-24 20:11 出处:网络
Why do most MVVM databinding properties examples check to see if the current value is equal to previous.开发者_Go百科

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号