100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
.NET

Silverlight Controls

An overview of Silverlight's built-in control library, the ContentControl/ItemsControl hierarchy, and event handling for common interactive controls.

UIBeginner10 min readJul 10, 2026
Analogies

The Silverlight Control Hierarchy

Silverlight ships a standard control library under System.Windows.Controls that inherits from a common Control base class, which itself derives from FrameworkElement. Controls split into two major families: ContentControl, which hosts a single piece of content (Button, CheckBox, ScrollViewer) via its Content property and can hold arbitrary UI rather than just text, and ItemsControl, which manages a collection of items (ListBox, ComboBox, DataGrid) via ItemsSource or an Items collection. Understanding this hierarchy explains why a Button can contain an Image and a TextBlock together, while a ListBox naturally repeats a DataTemplate per item.

🏏

Cricket analogy: ContentControl is like a single trophy display case that holds exactly one item, be it a bat or a medal, while ItemsControl resembles a team honors board that repeats the same display format for every player's individual stats.

Common Controls: Button, TextBox, ListBox

Button, a ContentControl, raises a Click event and supports the Command pattern only through custom attached behaviors since Silverlight lacks built-in ICommand binding on Button (that arrived later, in WPF and Windows Phone extensions). TextBox exposes Text, TextChanged, and selection properties, and by default updates its bound source only on LostFocus unless the binding explicitly specifies UpdateSourceTrigger where supported. ListBox derives from Selector, which derives from ItemsControl, adding SelectedItem, SelectedIndex, and a SelectionChanged event, and by assigning an ItemTemplate you control exactly how each bound object renders as a row.

🏏

Cricket analogy: A Button's Click event is like an umpire's finger going up the instant a batsman is given out, an immediate, unambiguous single event, whereas a TextBox that only commits its value on LostFocus is like a third-umpire review that only finalizes the decision after the players move away from the crease.

ItemsControl, DataTemplate, and DataGrid

When an ItemsControl (or its subclasses like ListBox and ComboBox) is bound via ItemsSource to a collection, each item is rendered using the ItemTemplate, a DataTemplate whose bindings resolve against the current item's properties. The Silverlight DataGrid (in System.Windows.Controls.Data) goes further, auto-generating columns from a bound object's public properties when AutoGenerateColumns is true, or accepting explicit DataGridTextColumn, DataGridCheckBoxColumn, and DataGridTemplateColumn definitions for full control over per-column rendering and editing.

🏏

Cricket analogy: DataGrid auto-generating columns from an object's properties is like a scorecard app automatically creating Runs, Balls, and Strike Rate columns just by reading a batsman's stat object, while explicit DataGridTemplateColumn definitions are like a broadcaster custom-designing a graphic overlay for a specific milestone.

csharp
// Code-behind: wiring ListBox selection and Button click
public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();
        CustomerList.ItemsSource = CustomerRepository.GetAll();
        CustomerList.SelectionChanged += CustomerList_SelectionChanged;
        SaveButton.Click += SaveButton_Click;
    }

    private void CustomerList_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (CustomerList.SelectedItem is Customer selected)
        {
            NameBox.Text = selected.Name;
        }
    }

    private void SaveButton_Click(object sender, RoutedEventArgs e)
    {
        if (CustomerList.SelectedItem is Customer selected)
        {
            selected.Name = NameBox.Text; // TextBox commits on LostFocus by default
            StatusText.Text = "Saved.";
        }
    }
}

Because Silverlight's Button has no built-in ICommand support, most MVVM implementations rely on an attached behavior (such as EventToCommand from the MVVM Light or Prism toolkits) to route Click into a ViewModel command.

Binding a TextBox's Text property without setting Mode=TwoWay leaves the control read-only from the source's perspective — edits typed by the user will not propagate back to the bound object even though the box visually accepts input.

  • All Silverlight controls derive from Control, which derives from FrameworkElement.
  • ContentControl hosts a single arbitrary piece of content via its Content property.
  • ItemsControl manages a collection via ItemsSource/Items and repeats an ItemTemplate per entry.
  • ListBox derives from Selector (itself an ItemsControl subclass), adding SelectedItem and SelectionChanged.
  • TextBox commits its Text to a TwoWay binding source on LostFocus by default.
  • DataGrid can AutoGenerateColumns from bound object properties or use explicit DataGridTemplateColumn definitions.
  • Silverlight's Button lacks native ICommand support, unlike later WPF/UWP command binding.

Practice what you learned

Was this page helpful?

Topics covered

#NET#SilverlightStudyNotes#MicrosoftTechnologies#SilverlightControls#Silverlight#Controls#Control#Hierarchy#StudyNotes#SkillVeris