我目前正在研究一种解决方案,该解决方案具有一组复合视图模型,这些视图模型是从一组数据访问服务返回的域模型映射的。
到目前为止,我INotifyPropertyChanged在基础 ViewModel 对象上实现并通过属性更改事件通知 UI 属性对象的更改方面取得了很大的成功。
这是视图模型的示例:
public class DisplayDataModel : INotifyPropertyChanged{ 
   private DateTime _lastRefreshTime;
    public DateTime LastRefreshTime {
        get { return _lastRefreshTime; }
        set {
            _lastRefreshTime = value;
            this.NotifyPropertyChanged(lddm => lddm.LastRefreshTime, PropertyChanged);
        }
    }
    private string _lineStatus;
    public string LineStatus {
        get { return _lineStatus; }
        set {
            if (_lineStatus != value) {
                _lineStatus = value;
                this.NotifyPropertyChanged(lddm => lddm.LineStatus, PropertyChanged);
            }
        }
    }           
    private ProductionBrickModel _productionBrick;
    public ProductionBrickModel ProductionBrick { 
        get { return _productionBrick;}
        set {
            if (_productionBrick != value) {
                _productionBrick = value;
                this.NotifyPropertyChanged(lddm => lddm.ProductionBrick, PropertyChanged);
            }
        }
    }
}
public class ProductionBrickModel{
    public int? Set { get; set; }
    public int? Theoretical { get; set; }
    public int? Actual { get; set; }
    public string LineName { get; set; }
    public TimeSpan? ShiftOverage { get; set; }
    public SolidColorBrush ShiftOverageBrush {
        get {
            if (ShiftOverage.HasValue && ShiftOverage.Value.Milliseconds < 0) {
                return Application.Current.FindResource("IndicatorRedBrush") as SolidColorBrush;
            }
            return Application.Current.FindResource("IndicatorWhiteBrush") as SolidColorBrush;
        }
    }
    public string ShiftOverageString { get { return ShiftOverage.HasValue ? ShiftOverage.Value.ToShortTimeSpanString() : ""; } }
}
所以目前我在基本模型而不是生产砖属性上触发通知事件,主要是因为生产砖属性几乎每次刷新都会改变。
最近,我开始将刷新时间缩短到 350 毫秒左右,我看到ShiftOverageBrush即使值仍然是负数,它也会在一瞬间变为白色。
我的问题是,通过INotifyPropertyChanged对构成基本视图模型的对象类型进行检查和实现,我会获得任何性能,甚至可能解决这个问题吗?或者这完全来自我不理解的其他东西?