Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

The ListBox Control

In the past, the list-box type of control has been considered one of the common controls in programming—no more special than a drop-down list. However, in Silverlight, this has all changed. The ListBox is perhaps one of the most flexible controls used to display lists of data. In fact, referring back to ASP.NET controls, the Silverlight ListBox is more a cousin to the DataList control than the ASP.NET ListBox control. Let’s take a peek at this powerful control.

Default and Custom ListBox Items

If you wire up the ListBox to your Person data from the earlier DataGrid example, you will see that, by default, the ListBox really is just a standard ListBox:

<ListBox Margin="10" x:Name="list" DisplayMemberPath="Name" />

One additional property you might have noticed in this ListBox definition is DisplayMemberPath. If you are defining a simple text-based ListBox, the ListBox needs to know which data member to display. Because the Person class contains three properties (Name, Age, and Male), you need to tell it that you want the Name to be displayed. Figure 5-14 shows the results.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint