- [Instructor] Let's take a look at a few different actual programmatic techniques that we would use when binding in a Universal Windows Platform app, and all of these are going to be XAML based. It's going to be outside the scope of this session, but everything that we're doing in XAML could be done in code-behind programmatically as well, so just keep that in mind. There are scenarios where code-behind programmatic binding does make sense. Let's walk through some of these. The first one is one that's newer. It's this dynamic x:Bind where we could just bind the property of some control to a specific property that's on our page or locally.
The example we used earlier is to a background color. We could just say the background color of this page is going to be bound to this property in my page. Or we could bind something to a ThemeResource, so the background could be a ThemeResource that we've named AppAccentBrush. Again, we could do the same thing for font families, where it could be a ThemeResource. The concept of ThemeResources is really just a clarification and a subset of the StaticResource, but in UWP development, we pretty much want to stick with theme resources that are related to styling like this.
Or we could bind a list control like a grid view, list view, list box, combo box, or anything that is collection based, to items, and we would simply just say, in brackets, binding items. Now, "items" is a value that would exist on our model that would be observable collection, or list, or an IEnumerable, something that is a collection that could be bound to, and remember that the label "items" is the name of the actual property in the class or on the model, or it could bind something to a StaticResource.
StaticResources are just as they sound. They're static. They don't typically get updated, so a StaticResource could be a style, a StaticResource could be a Template, a TemplateConverter. It could be a command or a value converter. StaticResources essentially get loaded up when the app gets run, and they pretty much stay as the same value, but you might want to be able to refer to that value in numerous places in your app, so you'd put it in a StaticResource. When we're binding, we could also bind with different types of parameter clarifications, so when we bind a text box, for example, we could say that we're binding it to a DisplayName, but we want the mode to be TwoWay, which means that it's in and out.
We're going to bind it when the control loads, and then when the value in the control changes, it's going to update it in our model, and there's a number of variations that we can work with here. We could even tell it how we want it to update, so for example, in a text box, do we want it to update when the property actually changes, or when the control loses focus, for example. We can do this in a number of different scenarios. Earlier in this series, we looked at binding simple things like an enabled property to another control, so we could say that when a check box is unchecked, then a group of controls below it are disabled, and when we check the box, then they become enabled.
The opportunities for data binding, and all other types of bindings in the Universal Windows Platform, are really almost unlimited. Why don't we do this? Let's flip over to Visual Studio to our tagger app we've been building in this series, and take a look at not just how we would implement binding in a Universal Windows Platform app, but we'll also take a look at some of the bindings that have already been implemented that I've skipped over in previous sessions.
Note: This course was created by Wintellect. We are pleased to host this training in our library.