Troubleshooting binding errors
As you may have noticed from previous recipes in this chapter, binding is one of the core mechanisms used in the MVVM pattern. Views in real apps include dozens of bindings and it’s important to know how to troubleshoot a binding when something doesn’t work.
One of the techniques that helps you avoid binding errors is assigning the x:DataType
attribute, which resolves bindings at compile time. This will not only let you know that you made a typo in a binding but will also improve the performance. However, x:DataType
only works when you know exactly what object will be used in BindingContext
. Sometimes, your binding source may contain properties with the object
type, and in such cases x:DataType
can’t be used. Moreover, you may need to create complex bindings with RelativeSource
and x:Reference
mechanisms, as described in the There’s more… section of the Decoupling the UI from the view model recipe in this chapter...