Understanding data binding in WinUI
In the previous chapter, you saw some simple examples of data binding, using both the Binding
and x:Bind
markup extensions. Let’s dissect some of the components that allow the View to receive updates when the View Model data changes.
What are markup extensions?
An in-depth discussion of markup extensions is beyond the scope of this introductory book. In brief, they are a class that executes some logic to return a value to the XAML parser. You can identify their use in XAML by looking for some markup inside curly braces. Take this example of Binding
in the Text
property of a TextBlock
:
<TextBlock Text="{Binding Path=Name, Mode=TwoWay}"/>
From this, you can derive that there is a markup extension class named Binding
and that two of its properties are Path
and Mode
. This markup extension takes these properties, resolves a value, and returns it to the XAML parser for display in the application’s View.
Some...