Silverlight Quick Reference
This reference condenses the syntax and rules a Silverlight developer looks up most often: core XAML layout elements, the data binding syntax and modes, the threading rule that governs every UI update, and the essential networking classes. It is meant as a fast lookup rather than a tutorial, assuming familiarity with the concepts covered in more depth elsewhere.
Cricket analogy: A fielding position cheat sheet pinned in the dressing room lets a captain make quick calls without re-deriving field theory each time, similar to this quick reference letting a developer look up Silverlight syntax fast.
XAML Layout Essentials
The core Silverlight layout panels are Grid (row/column layout via RowDefinitions and ColumnDefinitions), StackPanel (single-direction stacking via Orientation), Canvas (absolute positioning via Canvas.Left/Canvas.Top), and Border (a single-child decorator for background, border, and padding). Grid is the default choice for most real layouts because it resizes gracefully with the window, while Canvas should be reserved for cases needing pixel-precise absolute placement, such as custom drawing surfaces.
Cricket analogy: A well-marked cricket ground with defined zones for boundary, thirty-yard circle, and pitch resizes conceptually to any stadium size, similar to how Grid layout resizes gracefully compared to Canvas's fixed pixel placement.
Data Binding and Threading Cheat Sheet
Binding syntax is {Binding PropertyName, Mode=TwoWay, Converter={StaticResource MyConverter}}; the source object comes from DataContext unless ElementName or RelativeSource is specified instead. Every binding source class should implement INotifyPropertyChanged and raise PropertyChanged in every property setter. On the threading side, remember one absolute rule: only the UI thread may touch a UI element's properties, and any code running in a callback from WebClient, a background Thread, a Timer, or a Task must call Dispatcher.BeginInvoke to update the UI safely.
Cricket analogy: A clear team communication protocol where only the captain radios instructions to the field mirrors the strict rule that only the UI thread may update controls directly.
<StackPanel Orientation="Vertical" DataContext="{Binding Path=SelectedItem, ElementName=ItemsList}">
<TextBlock Text="{Binding Name}" />
<TextBox Text="{Binding Price, Mode=TwoWay, Converter={StaticResource CurrencyConverter}}" />
<ProgressBar Value="{Binding LoadPercent, Mode=OneWay}" Maximum="100" />
</StackPanel>Quick threading rule: if the code is running inside a *Completed event handler, a BackgroundWorker.DoWork delegate, a System.Threading.Timer callback, or any manually created Thread, wrap the UI-touching line in Dispatcher.BeginInvoke(() => { ... });.
Networking and Storage Cheat Sheet
For simple HTTP calls, use WebClient.DownloadStringAsync / UploadStringAsync paired with their *Completed events; for more control over headers and streaming, use HttpWebRequest.BeginGetResponse. For structured service calls, add a Service Reference to generate an async WCF proxy. Any call to a domain other than the one hosting the .xap requires a clientaccesspolicy.xml on the target server. For local persistence, use IsolatedStorageSettings.ApplicationSettings for simple key-value data or an IsolatedStorageFile stream for larger structured data, keeping the default 1 MB quota in mind.
Cricket analogy: Choosing a quick single for a simple run versus calling for a risky two mirrors choosing WebClient for simple calls versus HttpWebRequest for finer control over the exchange.
IsolatedStorageSettings.ApplicationSettings is convenient but not free of cost: every write serializes the entire settings dictionary. For frequently changing or large data, use an IsolatedStorageFile stream instead, and always check remaining quota with IsolatedStorageFile.AvailableFreeSpace before large writes.
- Grid is the default flexible layout panel; Canvas is for pixel-precise absolute positioning only.
- Binding syntax is {Binding Path, Mode=..., Converter={StaticResource ...}}; source classes need INotifyPropertyChanged.
- Only the UI thread may touch UI element properties; all other threads must use Dispatcher.BeginInvoke.
- WebClient is the simplest async HTTP option; HttpWebRequest offers finer control over headers and streaming.
- WCF service references generate async-only proxy methods for structured backend calls.
- Cross-domain calls require a clientaccesspolicy.xml hosted on the target server.
- IsolatedStorageSettings.ApplicationSettings suits small key-value data; use IsolatedStorageFile streams for larger data, respecting the 1 MB default quota.
Practice what you learned
1. Which layout panel should be used for pixel-precise absolute positioning in Silverlight?
2. What must a class implement to serve as a live-updating data binding source?
3. What must background thread code do before updating a UI element?
4. What is required for a Silverlight app to call a service hosted on a different domain?
5. What is the default isolated storage quota, and which API is best suited for small key-value settings?
Was this page helpful?
You May Also Like
Silverlight Common Pitfalls
A field guide to the mistakes developers repeatedly make when building Silverlight applications, covering data binding, threading, and deployment traps.
Silverlight Debugging
Practical techniques for diagnosing binding failures, cross-thread exceptions, and network issues in Silverlight applications using Visual Studio and browser tools.
Silverlight Interview Questions
Commonly asked Silverlight interview questions covering the runtime model, XAML, data binding, and threading, with the reasoning behind strong answers.
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