How Do I refresh window in wpf?
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.
开发者_如何学PythonHow can I do this in code?
Thanks
Is the list an ObservableCollection
or properties implementing INotifyPropertyChanged
?
Have you tried:
myDatagrid.Items.Refresh();
Maybe:
this.NavigationService.Refresh();
or
this.NavigationService.Navigate(new Uri("<EnterPage name here.xaml", UriKind.Relative));
I used this workaround, it's no perfect but works
MainWindow newWindow = new MainWindow();
Application.Current.MainWindow = newWindow;
newWindow.Show();
this.Close();
this might be of interest to you: How to preserve control state within tab items in a TabControl
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.
精彩评论