QA Friday 2016-Jun-24

Take Up Code - En podcast af Take Up Code: build your own computer games, apps, and robotics with podcasts and live classes

Kategorier:

What is data binding? A good example of this is a list box that shows several items. If you’re writing a list box that can only show an alphabetical list of country names, it won’t be very useful in other applications. It would be really bad if anytime we wanted to use a list box, we had to write it all over again for each scenario. List boxes normally have methods you can call to add and remove items displayed. That’s not data binding though. A list box capable of data binding will have a property such as dataSource. All you have to do is point the list box to the source of the data and it can go get the items to be displayed itself. This really helps simplify your code. All you have to do is change sources and you get new data. But if there’s a bigger benefit, it has to be that the link between the consumer of the data and the source of the data can remain even though the data itself changes. This is called a master-details pattern. You need a data source of all the items and you start out by setting the data source for your list control to this source. But you also need to tell it what properties to use. Maybe the data source has many different collections of items. You need to let the list box know which property on the source has the data it needs to display. You can get as specific as you need and you might also need to tell the list box which property to use as a unique identifier and which property to use for the display text. Users don’t normally care about identifiers. They just want a friendly name for things. Listen to the episode or read the full transcript below for additional benefits to using data binding. Transcript Imagine you work for a construction company and your job is to gather information about how many cars pass by with just a single passenger. Your company needs this information to plan the best way to build roads and you can’t use the automatic counters because they count too many vehicles. All you really need to do is take notes and write a report each day about what you saw. You don’t look everywhere at once. You’re given a specific location to observe each day. The work is the same and the only thing that’s different is where you get your information. Over time, you get really good at this. Almost as if you just run a mental program. I know, that’s a strange example. But it does represent the essentials of data binding. You have some code that performs some task and needs data. Where it gets the data can change without affecting the code. In other words, the data is bound to a particular source and then later to another source. A good example of this in programming is a list box that shows several items. If you’re writing a list box that can only show an alphabetical list of country names, it won’t be very useful in other applications. It would be really bad if anytime we wanted to use a list box, we had to write it all over again for each scenario. List boxes normally have methods you can call to add and remove items displayed. That’s not data binding though. A list box capable of data binding will have a property such as dataSource. All you have to do is point the list box to the source of the data and it can go get the items to be displayed itself. This really helps simplify your code. All you have to do is change sources and you get new data. But if there’s a bigger benefit, it has to be that the link between the consumer of the data and the source of the data can remain even though the data itself changes. Have you ever used an application that presents a list of items and allows you to select one and get more information about it? Sure you have. Even this podcast is a list of episodes and once you select an episode, you can see details about the episode and play it. This can all be done with data binding. And I’ll explain how right after this message from our sponsor. A source of information can suppl

Visit the podcast's native language site