Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Can I force a window to re-evaluate all of its bindings and validations?

Tags:

binding

wpf

Can I force a window to re-evaluate all of its bindings and validations?

For some reason it seems to be ignoring the INotifyPropertyChanged.PropertyChanged in one weird situation and I'm looking for a work-around to use until I find the real cause.

like image 701
Jonathan Allen Avatar asked Oct 09 '10 01:10

Jonathan Allen


2 Answers

Unfortunately, I know of no way to force every binding within a window to re-evaluate. Part of the problem is that most of the bindings aren't declared on the Window, but rather on specific DependencyObject children of the Window.

You can use DependencyObject.InvalidateProperty to invalidate a single binding, but this must be done on a property by property basis. If there is only a few objects being bound, you should be able to use this to force a requery of their values.

That being said, I would suggest figuring out the root cause - it's likely to be a better solution in the long run.

like image 197
Reed Copsey Avatar answered Nov 01 '22 03:11

Reed Copsey


Raise PropertyChanged with String.Empty as the property name. This will cause all bindings in the object to reread all its bindings.

If you are having binding issues dont forget to check your Output window for binding errors

like image 30
benPearce Avatar answered Nov 01 '22 03:11

benPearce