首先,我的英语很弱,希望你可以低调! 我正在使用DomainServices(DomainContext类 - 命名空间:System.ServiceModel.DomainServices.Client)开发一个silverlight应用程序来检索和更新数据。 我有一些属性:
DomainContextVBHS _Service = new DomainContextVBHS();
public int AddedEntitiesCount
{
get{ return _Service.EntityContainer.GetChanges().AddedEntities.Count; }
}
public int ModifiedEntitiesCount
{
get{ return _Service.EntityContainer.GetChanges().ModifiedEntities.Count; }
}
public int RemovedEntitiesCount
{
get{ return _Service.EntityContainer.GetChanges().RemovedEntities.Count; }
}
当_Service获得任何更改时,我如何在UI上通知他们?
答案 0 :(得分:0)
更新:示例代码:https://dl.dropboxusercontent.com/u/8424800/StackOverflowHasChanges.zip
我使用反编译器快速查看了源代码。没有正式的方式可用。幸运的是,如果您愿意听取所有内部实体集上的所有属性更改事件,您应该能够实现您所追求的目标。
public class Sample:INotifyPropertyChanged {
SampleDomainContext _Service = new SampleDomainContext();
public Sample()
{
_Service.Load(_Service.GetCustomersQuery());
_Service.Customers.PropertyChanged += PropChanged;
//_Service.Orders.PropertyChanged += PropChanged;
// etc.
}
public int AddedEntitiesCount
{
get { return _Service.EntityContainer.GetChanges().AddedEntities.Count; }
}
public int ModifiedEntitiesCount
{
get { return _Service.EntityContainer.GetChanges().ModifiedEntities.Count; }
}
public int RemovedEntitiesCount
{
get { return _Service.EntityContainer.GetChanges().RemovedEntities.Count; }
}
public void PropChanged(object sender, PropertyChangedEventArgs e)
{
var pc = this.PropertyChanged;
if (pc != null)
{
pc(this, new PropertyChangedEventArgs("AddedEntitiesCount"));
pc(this, new PropertyChangedEventArgs("ModifiedEntitiesCount"));
pc(this, new PropertyChangedEventArgs("RemovedEntitiesCount"));
// etc
}
}
public event PropertyChangedEventHandler PropertyChanged;
}