When I wish to bind a control to a property of my object, I have to provide the name of the property as a string. This is not very good because:
- If the property is removed or renamed, then I don’t get a compiler warning.
- If a rename the property with a refactoring tool, then it is likely the data binding will not be updated.
- If the type of the property is wrong, e.g. binding an integer to a date chooser, then I don’t get an error until runtime.
Is there a design-pattern that gets round this, but still has the ease of use of data-binding?
(This is a problem in WinForms, ASP.NET, and WPF and possibly other systems.)
I have now found "workarounds for nameof() operator in C#: typesafe databinding" that also has a good starting point for a solution.
If you are willing to use a post processor after compiling your code, then NotifyPropertyWeaver is worth looking at.
Does anyone know of a good solution for WPF when the bindings are done in XML rather than C#?