How to force bind WPF to update?

I have a combo box with a source of the source associated with using a simple binding. Is there any way to update this binding after loading combo fields?

+75
c # data-binding wpf
Apr 15 '11 at 11:45
source share
6 answers

You can use binding expressions:

private void ComboBox_Loaded(object sender, RoutedEventArgs e) { ((ComboBox)sender).GetBindingExpression(ComboBox.ItemsSourceProperty) .UpdateTarget(); } 

But as Blindmeis noted , you can also activate change notifications, if your collection implements INotifyCollectionChanged (for example, implemented in ObservableCollection<T> ), it will be synchronized so you do not need to do anything.

+134
Apr 15 '11 at 11:50
source share

if you use mvvm and your items source is in your vm. just call INotifyPropertyChanged for your collection property if you want to update.

 OnPropertyChanged("YourCollectionProperty"); 
+41
Apr 15 '11 at 12:18
source share

To add my 2 cents, if you want to update your data source with the new value of your control, you need to call UpdateSource() instead of UpdateTarget() :

 ((TextBox)sender).GetBindingExpression(ComboBox.TextProperty).UpdateSource(); 
+21
Feb 09 '14 at 5:48
source share

Universal version of MultiBinding ...

 private void ComboBox_Loaded(object sender, RoutedEventArgs e) { BindingOperations.GetBindingExpressionBase((ComboBox)sender, ComboBox.ItemsSourceProperty).UpdateTarget(); } 
+6
Jun 08 '16 at 1:31 on
source share

Try using BindingExpression.UpdateTarget ()

+5
Apr 15 2018-11-11T00:
source share

I retrieved data from the backend and updated the screen with just one line of code. It worked. Not sure why we need to implement the interface. (windows 10, UWP)

  private void populateInCurrentScreen() { (this.FindName("Dets") as Grid).Visibility = Visibility.Visible; this.Bindings.Update(); } 
-one
Oct. 16 '16 at 7:18
source share



All Articles