I want to bind some column data of readonly DataGrid to Association property of Entity through Converter (convert collection from this association property to string). Wh开发者_JAVA技巧en I try to add/remove elements from collection, binding don't fire. PropertyChanged also, don't rising.
contractPosition.PropertyChanged += (s, e2) =>
{
a = 0;//don't fire
};
contractPosition.ContractToOrderLinks.Remove(link);
Here is the fragment of contractPosition Entity (generated by EF4):
[Association("ContractPosition_ContractToOrderLink", "PositionId", "ContractPositionId")]
[XmlIgnore()]
public EntityCollection<ContractToOrderLink> ContractToOrderLinks
{
get
{
if ((this._contractToOrderLinks == null))
{
this._contractToOrderLinks = new EntityCollection<ContractToOrderLink>(this, "ContractToOrderLinks", this.FilterContractToOrderLinks, this.AttachContractToOrderLinks, this.DetachContractToOrderLinks);
}
return this._contractToOrderLinks;
}
}
Why PropertyChanged don't rise? How can I implement binding refresh?
There are a few different events to listen to:
INotifyPropertyChanged.PropertyChangedFires when the value of
_contractToOrderLinkschanges. In your sample code, the value never changes, the event is never called, and the event never fires.INotifyCollectionChanged.CollectionChangedFires when an object is added, an object is removed and, when the collection is cleared.
EntityCollection<>.EntityAddedFires when an object is added.
EntityCollection<>.EntityRemovedFires when an object is removed. I am not sure if this fires for each entity when the collection is cleared.
I prefer to use the INotifyCollectionChanged.CollectionChanged event. However, EntityCollection<> explicitly implements the interface so you must cast it first. Try this:
((INotifyCollectionChanged)contractPosition.ContractToOrderLinks).CollectionChanged += (s, e) =>
{
a = 0; //does fire
};
contractPosition.ContractToOrderLinks.Remove(link);
加载中,请稍侯......
精彩评论