Pinpointing data binding failures
While debugging data binding problems is not as difficult in WinUI and UWP as it is in WPF (if you use
x:Bind-compiled bindings), there are still some gotchas to avoid. In this section, we will look at what can go wrong in views and ViewModels and how you can diagnose and fix the problems.
Common mistakes in data binding
If you use
x:Bind, the compiler will evaluate whether you’re binding to a valid source and can give you the peace of mind of knowing that your views and ViewModels are hooked up correctly, but there is still a lot that can go wrong. Let’s review a few of the most common mistakes.
Selecting the best binding mode
We have seen in previous chapters that the default mode for most controls with
OneTime, while the default for
OneWay. Defaulting to
OneTime helps with performance as many read-only properties are only ever set when the view is first created. However, if you forget to change this...