Items in Datagrid not updating on all clients once ObservableCollection has been updated
I am using SL4, MVVM Toolkit, Entity Framework 4 & WCF RIA Services. I have a grid whose DataSource is an Observab开发者_高级运维leCollection<Ticket>
. The Ticket OC is populated by a RIA Service:
private void LoadTickets()
{
IsBusy = true;
_Context.Load(_Context.GetOpenTicketsForUserQuery(Session.UserId), GetTicketsCallback, null);
}
private void GetTicketsCallback(LoadOperation<Ticket> lo)
{
ListOfTickets = (ObservableCollection<Ticket>)lo.Entities;
}
When I add a new Ticket object to the OC the grid shows the new item on all clients once I refreh the grid ( Every 30 seconds I refresh the grid for each client by calling LoadTickets()
). This works if I remove an item from the grid as well. However, when I update a property in the Ticket object and Save it ( Call SubmitChanges() on the DataContext ) this change does NOT show on the other clients even after I refresh the grid. I have to refresh the whole page in the browser to see the changes. I have read many similar questions on here and they all say you must implement INotifyPropertyChanged on your object properties as well as the ObservableCollection.
But, AFAIK the Entity Framework does this automatically !? I can see all my properties in the Model Designer.cs and they all raise a PropertyChanged event when the property is set. I'm just wondering if this has something do with the fact I am using RIA Services ? I have tried adding a property from my Ticket object to my RIA Service Metadata and calling the RaisePropertyChanged() event from here but it didn't work either.
[MetadataTypeAttribute(typeof(TicketMetadata))]
public partial class Ticket
{
internal sealed class TicketMetadata : NotifiableObject
{
[Required]
[StringLength(255, MinimumLength=15)]
public string TicketSummary
{
get { return TicketSummary; }
set
{
TicketSummary = value;
RaisePropertyChanged("TicketSummary");
}
}
}
}
Can anyone shed any light on this for me? It's driving me crazy!! I'm new to Silverlight Development so apologies if this is a stupid question :)
Ok - I got to the bottom of this. In the Load() event I need to set the LoadBehaviour
_Context.Load(_Context.GetOpenTicketsForUserQuery(Session.UserId), LoadBehavior.MergeIntoCurrent, GetTicketsCallback, null);
This has resolved my issue.
精彩评论