UP Computer Science Interns' Blog

May 14, 2010

Data Binding

Filed under: mic_200706692 — lcprospero @ 5:10 pm
Tags: , ,

Last Tuesday, we continued working on our projects. It was challenging since C# wasn’t nice to me, plus Visual Studio has still a lot of secrets; Blend just don’t blend with my project.

I almost gave up with the Multipoint-based Classroom Elections because of the dynamic-number-of-buttons problem. I can, but I just couldn’t think of a better way than doing it the brute force way — adjusting the buttons pixel by pixel, aligning them to other buttons, etc. I could have chosen the Feedback Form or the Multiplayer Game since it will be more static in some way.

In the afternoon, Sir Tim came to the office to check on us. He was chatting with the Student Partners (yes, Jase was here) who arrived earlier so I didn’t dare to disturb them or care to ask about the problem (or let’s just say, I was waiting for him to ask how we were doing).

Finally! He approached us. So I told him about my dynamic-number-of-buttons problem. He said I wasn’t maximizing XAML. — (O.o) Anyway, at least he didn’t stop there. He took my place and grabbed the mouse.

He showed us a feature in Blend(C#) using a WPF application and called it data binding. He created a sample data source and dragged it to a ListBox. Then there was the dynamic list . (-__-)

Data Binding

Notice that the right side displays a panel called Data. The SampleDataSource contains a Collection with two properties — an Image and a Boolean property. When bound to the ListBox in the main window, the sample data was reflected on the container — images of chairs and checkboxes.

Through data binding, you can bind data (as the name itself) to a container such as a ListBox or ListView. Whatever you do to the container, you do it too on the content. If, for example, you apply an animation on the ListBox, the contents will also animate during the execution of the effect.

It adds flexibility to your UI and adds “dynamicity” on the objects. If you look at it on the other way, like what Sir Tim mentioned, it’s like the MVC architecture. The Data is your Model, the code in the .cs file is your Controller, and the UI on the XAML file serves as the View.

Two new lessons. First, WPF supports data binding, which is a very useful feature. Ssecond, ask before they sense it.


Blog at WordPress.com.

%d bloggers like this: