Comment appeler UpdateSource pour toutes les liaisons du formulaire?

Comment appeler UpdateSource pour toutes les liaisons du formulaire?

Il y a quelque temps, j’ai écrit un groupe d’auxiliaires pour cette tâche.

public static void UpdateAllBindingSources(this DependencyObject obj) { foreach (var binding in obj.GetAllBindings()) binding.UpdateSource(); } public static IEnumerable GetAllBindings(this DependencyObject obj) { var stack = new Stack(); stack.Push(obj); while (stack.Count > 0) { var cur = stack.Pop(); var lve = cur.GetLocalValueEnumerator(); while (lve.MoveNext()) if (BindingOperations.IsDataBound(cur, lve.Current.Property)) yield return lve.Current.Value as BindingExpression; int count = VisualTreeHelper.GetChildrenCount(cur); for (int i = 0; i < count; ++i) { var child = VisualTreeHelper.GetChild(cur, i); if (child is FrameworkElement) stack.Push(child); } } } 

Alors tu appelles

  this.UpdateAllBindingSources (); 

de votre fenêtre et vous avez terminé.