Learning to pinpoint data binding errors
While debugging data binding problems is not as difficult in WinUI and UWP as it is in WPF, thanks to x:Bind
compiled bindings, there are still some gotchas of which you should be aware. In this section, we will look at what can go wrong in both views and ViewModels and how you can diagnose and fix the problems.
Common mistakes in data binding
Using x:Bind
will evaluate whether you're binding to a valid source at compile time and can give you the peace of mind to know 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 x:Bind
is OneTime
, while the default for Binding
is 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...