我有一个 WPF 窗口并给它一个 DataContext,当目标更改时它运行良好(通过使用UpdateSourceTrigger
),但是当 DataContext 属性(源)之一更改时,目标不会更新。有没有办法在源更新时强制目标绑定更新?一件物品有类似ObservableCollection
的东西吗?
这是我的课:
public class PaymentDetailInfo : INotifyPropertyChanged
{
public Payment Payment
{
get;
set;
}
public int SumOfValidNormalOverTimePrice
{
get
{
return 100 * Payment.ConsideredValidNormalOverTime / 60;
}
}
public int SumOfInvalidNormalOverTimePrice
{
get
{
return 100 * Payment.ConsideredInvalidNormalOverTime / 60;
}
}
public int SumOfOverPriceConst
{
get
{
int _sumOfOverPriceConst = 0;
if (!Payment.ValidNormalOverTimePriceIsPercent)
_sumOfOverPriceConst += SumOfValidNormalOverTimePrice;
if (!Payment.InvalidNormalOverTimePriceIsPercent)
_sumOfOverPriceConst += SumOfInvalidNormalOverTimePrice;
_sumOfOverPriceConst += Payment.RewardPrice;
return _sumOfOverPriceConst;
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null)
PropertyChanged(this, e);
}
}
我的窗口中的某些元素绑定到Payment
(PaymentDetailInfo
付款是数据库表),因此作为示例用户可以更改Payment.ConsideredValidNormalOverTime
然后PaymentDetailInfo.SumOfValidNormalOverTimePrice
将更改然后PaymentDetailInfo.SumOfOverPriceConst
将更改。PaymentDetailInfo.SumOfOverPriceConst
但是,即使我的表单的数据上下文已更新,绑定到的目标也不会更新。