July 12, 2008

WPF: Binding an array of objects to a ListBox

Posted in Databinding, ListBox, Uncategorized, WPF tagged , , , at 11:23 pm by Mike

One way Windows Presentation Foundation (WPF) brings data to a user is through data binding. This post creates an object bounded example program using a WPF ListBox.  The example uses a typical Model-View-Controller  architecture.

Description:

Imagine receiving the task of displaying some array of objects.  One approach would be to iterate over the array and perform a “toString” on each object outputting the concatenation of all strings.  This is silly, let alone plain inefficient. Sure, if what needs to be displayed changes you can simply update the respective object’s toString implementation and be done. However, if the object has changed such that representing it by a simple string is not descriptive enough, then there is a big problem.  A lot of pieces will have to change in order to accommodate the displaying of the array in some other way. Using the M-V-C architecture creates a helpful layering of business and visual logic specific operations giving some of the wanted flexibility.

Read the rest of this entry »