【发布时间】:2013-03-21 17:34:26
【问题描述】:
我目前正在研究一种解决方案,该解决方案具有一组复合 ViewModel,这些 ViewModel 映射自从一组数据访问服务返回的域模型。
到目前为止,我在基本 ViewModel 对象上实现 INotifyPropertyChanged 并通过属性更改事件通知 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 并实现任何性能,甚至可能解决这个问题吗?或者这完全来自其他我不理解的东西?
【问题讨论】:
标签: c# data-binding inotifypropertychanged wpf-4.0