Understanding data binding in WinUI
In the previous chapter, you saw some simple examples of data binding, using both the Binding
and newer x:Bind
markup extensions. Let's dissect some of the pieces that allow the View to receive updates when the ViewModel 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 x:Bind
in the Text
property of TextBlock
:
<TextBlock Text="{x:Bind 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 XAML markup...