title: How to make Databinding type safe and support refactoring?
body: <p>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:</p>
  
  <ol>
  <li>If the property is removed or renamed, then I don’t get a compiler warning. </li>
  <li>If a rename the property with a refactoring tool, then it is likely the data binding will not be updated.</li>
  <li>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.</li>
  </ol>
  
  <p>Is there a design-pattern that gets round this, but still has the ease of use of data-binding?</p>
  
  <p>(This is a problem in WinForms, ASP.NET, and WPF and possibly other systems.)</p>
  
  <p>I have now found "<a href="https://stackoverflow.com/questions/301809/workarounds-for-nameof-operator-in-c-typesafe-databinding">workarounds for nameof() operator in C#: typesafe databinding</a>" that also has a good starting point for a solution.</p>
  
  <p>If you are willing to use a post processor after compiling your code, then <a href="https://github.com/shiftkey/NotifyPropertyWeaver" rel="nofollow noreferrer">NotifyPropertyWeaver</a> is worth looking at.</p>
  
  <hr>
  
  <p>Does anyone know of a good solution for WPF when the bindings are done in XML rather than C#?</p>