Click here to Skip to main content
15,902,886 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
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 .

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

I Then did add operation using this code:
Task t = new Task();
t.ID = 10;
t.Title = "Task1";

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 :

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

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

t.ID = 10;
t.Title = "Task1"

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.

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