- Is the binding setup correctly (Binding is failing) : Misspelled names, incorrect DataContext can be first culprit for binding not working. This can be determined by looking at the output window while debugging the application. Each failing binding would be logged in the output window. Remember databinding are reevaluated anytime DataContext changes. If you are setting up DataContext in code, look for binding failure just after DataContext is assigned. Some of the most common reason for binding failures are
- Misspelled member variable names. Very easy to detect
- Incorrectly declare a Public property as Public field (no get;set;). AFAIK databinding works only on public properties
- Declaring member as internal or with more restricted accessors.
- Using incorrect DataContext. DataContext assigned at parent control level can directly affect the DataContext of a child control if child is not bounded to a specific DataContext explicitly. Therefore any parent DataContext change can invalidate the child control binding.
- Binding not failing but data not getting updated: There can be numerous reasons for this. You may not see any binding failures in the output window specific to your binding but neither the source or target are getting updated. Some of the most common reason for this is
- Binding mode may be incorrect. Check documentation for binding mode and use a appropriate binding accordingly.
- Check for UpdateSourceTrigger Property of binding is setup correctly.
- Value being assigned from source to target or vice versa is incompatible. You can use a debugging converter to see what values are being passed from source to target. More details about this are available on this blog entry.
- Does the binding contain any validation rules. In case binding contains validation rules, any update on target( mostly UI element) will reevaluate the rule and if the rule fails source(entity) would not be update.
- Incorrect DataContext assignment. This is a little difficult to find. Make sure that the DataContext used in databinding is pointing to the correct entity (or source). You may be expecting a different source to be updated and you have done databinding to a different source. DataContext assignments in code should be thoroughly evaluated.
Hope this list may help everyone debug their databinding issues. Some the stuff here is derived from an excellent blog entry by Bea Stollnitz