您可以随时触发,PropertyChanged
绑定引擎将更新 UI。
不需要在属性设置器中执行此操作。因此,在您计算的方法中,total
只需使用您计算的属性名称引发事件D_F_Percent
。
参见示例 CalculateTotal
方法:
public class ViewModel : INotifyPropertyChanged
{
private double d_f;
public double D_F
{
get { return d_f; }
set { d_f = value; FirePropertyChanged("D_F"); }
}
private double total;
public double Total
{
get { return total; }
set { total = value; FirePropertyChanged("Total"); }
}
public Double D_F_Percent
{
get { return d_f / total; }
}
public void CalculateTotal()
{
//Do some calculation set total
FirePropertyChanged("D_F_Percent");
}
public event PropertyChangedEventHandler PropertyChanged;
public void FirePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}