Silverlight – ListBox

Silverlight – ListBox

Listbox is a control that provides a list of items to the user for selection of an item. A user can select one or more items from a predefined list of items at a time. In a ListBox, multiple options are always visible to the user without any user interaction.

A Listbox presents a scrollable list of items. If a user selects an item, the selected item changes appearance to indicate selection. It supports a more extensive form of content model and Button. A major difference between a button and a list box is that a button contains a single piece of content whereas a listbox allows every single item in the list.

The hierarchical inheritance of ListBox class is as follows −


Given below are the commonly used Properties of ListBox class.

Given below are the most commonly used Events of ListBox.

Given below are the most commonly used Methods of ListBox.

Let us look at a simple example in which different UI elements are added in a ListBox.

<UserControl x:Class = "ListBoxExample.MainPage" 
   xmlns = ""  
   xmlns:x = "" 
   xmlns:d = "" 
   xmlns:mc = ""  
   mc:Ignorable = "d" d:DesignWidth = "640" d:DesignHeight = "480"> 
   <Grid x:Name = "LayoutRoot">
      <ListBox x:Name = "myList">
         <TextBlock Text = "First item" /> 
         <Button Content = "Second item" /> 
         <Path Fill = "Blue" Data = "M4,0 l-4,10 8,0z M15,0 l-4,10 8,0z M26,0 l4,10 8,0z" 
            Margin = "10" /> 
         <StackPanel Orientation = "Horizontal"> 
            <Ellipse Fill = "Red" Height = "30" Width = "100" /> 
            <TextBlock Text = "Name: " /> 
            <TextBox Width = "200" /> 
         <TextBlock Text = "More..." /> 

Given below is the C# implementation.

using System.Windows.Controls; 
namespace ListBoxExample { 

   public partial class MainPage : UserControl { 
      public MainPage() { 
         myList.Items.Add("String entry"); 
         myList.Items.Add(new Button { Content = "Content entry" });  

When the above code is compiled and executed, you will see a list box which contains mixture of graphics text and also an editable field where you can type the text.


Sr. No. Controls & Description
1 Calendar & DatePickerCalendar & DatePicker represents a control that enables a user to select a date by using a visual calendar display. It provides some basic navigation using either the mouse or the keyboard.
2 TabControlA container that places items into separate tabs and allows the user to view just one tab at a time. It allows the user to select from a number of different views by clicking on the tab headers.
3 PopupThis class displays the content on top of the existing content, within the bounds of the application window. It is a temporarily display on the other content.
4 ToolTipTooltip represents a control that creates a pop-up window that displays information for an element in the GUI. Silverlight lets you attach a tooltip to any control.

Was this article helpful?

Related Articles

Leave A Comment?