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.
// 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
1. Which base class does Button ultimately derive from that lets it host arbitrary content like an Image and TextBlock together?
2. By default, when does a TextBox bound with Mode=TwoWay push its Text value to the bound source?
3. Which class does ListBox derive from that adds SelectedItem and SelectionChanged?
4. What does setting AutoGenerateColumns=true on a DataGrid do?
5. Why do MVVM frameworks typically add an attached behavior for Button in Silverlight?
Was this page helpful?
You May Also Like
Silverlight Data Binding
How the Binding markup extension connects XAML UI elements to CLR objects, with INotifyPropertyChanged, converters, and validation driving live, two-way updates.
Silverlight Layout Panels
How Grid, StackPanel, Canvas, and other panels arrange and size Silverlight UI content through the measure/arrange layout pass.
Silverlight Styles and Templates
How Style setters standardize appearance across controls, and how ControlTemplate replaces a control's entire visual structure while VisualStateManager drives its states.
Related Reading
Related Study Notes in Microsoft Technologies
Browse all study notesWindows 10 / UWP Development Study Notes
.NET · 30 topics
Microsoft TechnologiesWindows Batch Scripting Study Notes
Batch · 30 topics
Microsoft TechnologiesMFC (Microsoft Foundation Classes) Study Notes
C++ · 30 topics
Microsoft TechnologiesXAML Study Notes
.NET · 30 topics
Microsoft TechnologiesWPF (Windows Presentation Foundation) Study Notes
.NET · 30 topics
Microsoft TechnologiesMVVM Design Pattern Study Notes
.NET · 30 topics