I have a class Item
. My window shows a TreeView with those items and there is a details form on the right (to edit the name of the Item
).
Anyway, when I edit the item name in the TextBox and then press Cancel button (which calls Context.Refresh(Sto开发者_JAVA百科reWins, myItemEntity)
) the UI does not get updated with old values from the database right away - I have to switch e.g. to another entity in the tree and then it gets updated.
What seems to be the problem here?
Just to complete this question.
In my case the problem was that the TreeView was actually bound to an object that containes the item property, e.g.:
class ItemContainer
{
public Item Item { get; set; }
}
So it was a navigation property of another entity. This said we can say that TreeView does not, obviously check the changes in props and EntityObject class does not fire a PropertyChanged event when a navigation property changes. The fix for this is to either have an alternative property (that is not autogenerated by EF) that would fire the OnPropertyChanged inside of AssociationChanged event handler.
Or if using POCO it is even simplier - in your virtual property Item you can fire the OnPropertyChanged right away :)
精彩评论