Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi.
I am developing an WPF application that connect to a sql server database by EntityFramework . I have a table in my database named Tasks .I have a Treeview control in my wpf application that is bound to my Task entity in EntityFramework model .
First I bound TreeView to Task entity using this code .

C#
MyEntity myEntity = new MyEntity();
myTreeView.ItemsSource = myEntity.Tasks;


I Then did add operation using this code:
C#
Task t = new Task();
t.ID = 10;
t.Title = "Task1";
myEntity.Tasks.Add(t);
myEntity.SaveChanges();


I noticed that this code updated my database but did not update UI automatically until I restart my application . Then I used this code to overcome this problem :

C#
IBindingList _bindingList;
_bindingList = ((IListSource)myEntity.Tasks).GetList() As IBindingList;
myTreeView.ItemsSource = _bindingList;


Now When I add a Task it works (It updates UI):

C#
t.ID = 10;
t.Title = "Task1"
_bindingList.Add(t);
myEntity.SaveChanges();


My problem is here . This application has been used by two persons on two computers in our local network . When person1 add a task it does not update UI in person2 application . I Have tried Mode = TwoWay in xaml but this did'nt change anything .

How can I reflect changes in my application UI in computer 1 whenever a change is applied in my Database by computer 2?

Sorry for my too long question and thanks for your answers.
Posted

1 solution

Are you implementing INotifyPropertyChanged or INotifyCollection changed appropriately.

When you bind a WPF object to a CLR object and the CLR object changes and you want to update the UI, you have to properly implement INotifyproperty changed because common CLR properties are not dependency properties. Only then a two way binding wil work.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900