12

I have a small project I am working on which is a window with 4 WPF tabs on it.

The first tab is where I do most of the work, but occasionally I need to move back to other tabs. One of these tabs has a DataGrid that is bound to a list that is affected by the main tab I stay on.

When I update something on the first tab, I need it to cause a refresh on the data in the Datagrid(usually just to update a value).

The only way it has been working is if I click on the header myself.

How can I do this in code?

Thanks

TheJediCowboy
  • 8,924
  • 28
  • 136
  • 208

5 Answers5

7

Is the list an ObservableCollection or properties implementing INotifyPropertyChanged?

Have you tried:

myDatagrid.Items.Refresh();
Gabe
  • 49,577
  • 28
  • 142
  • 181
4

Maybe:

this.NavigationService.Refresh();

or

this.NavigationService.Navigate(new Uri("<EnterPage name here.xaml", UriKind.Relative));
Filip Krstic
  • 713
  • 7
  • 19
  • 1
    Note for new visitors : This will not apply for regular Window controls. Mainly deals with Page, Frame, NavigationWindow. Read more in MSDN about how it works. http://msdn.microsoft.com/en-us/library/ms750478(v=vs.110).aspx – Sai Jul 31 '14 at 19:42
3

I used this workaround, it's no perfect but works

MainWindow newWindow = new MainWindow();
Application.Current.MainWindow = newWindow;
newWindow.Show();
this.Close();
Antonio Reyes
  • 516
  • 4
  • 7
1

this might be of interest to you: How to preserve control state within tab items in a TabControl

Community
  • 1
  • 1
1

If you are working on an Object that you are displaying shared properties you could implement the INotifyPropertyChanged interface and refresh the DataGrid. If its a collection you could look at the ObservableCollection class.

Lloyd
  • 2,932
  • 2
  • 22
  • 18