我会这样做:
public bool PositionModifiedByUser
{ /* implement IPropertyChanged if need to bind to this property */ }
// use this property from code
public double Position
{
get { return m_position ; }
set { SetPropertyValue ("PositionUI", ref m_position, value) ;
PositionModifiedByUser = false ; }
}
// bind to this property from the UI
public double PositionUI
{
get { return m_position ; }
set { if (SetPropertyValue ("PositionUI", ref m_position, value))
PositionModifiedByUser = true ; }
}
SetPropertyValue 是一个帮助器,它检查是否相等并在值实际更改时触发属性更改通知。