Any Silverlight application will have at least one class which extends the UserControl parent. For example, a new C# Silverlight project will define a class such as the following:
Code Snippet
- namespace TesterSLApp
- {
- ????public partial class MainPage : UserControl
- ????{
- ????????public MainPage()
- ????????{
- ????????????InitializeComponent();
- ????????}
- ????}
- }
Like any base class, UserControl defines a polymorphic interface to derived types. As it turns out, UserControl extends a number of additional classes, all the way to our good friend System.Object. The fill inheritance chain looks like so:
The UserControl parent class allows derived types to host ?content?. The Silverlight content model demands that a UserControl specifies a single piece of content. Most often, the ?single piece of content? will be a layout manager containing all the UI elements, vector graphics, etc. Beyond this (very important) aspect, UserControl brings little to the table.
In addition to the Content property of UserControl, be aware that a majority of Silverlight controls extend the ContentControl parent class. This class also defines a Content property for a similar purpose. For example, the Button class extends ContentControl, and therefore can participate in the Silverlight content model.
By way of an example, a Button could maintain an inner StackPanel as ?content?. The StackPanel contains an Ellipse and TextBlock. Here is a simple example in XAML.
Code Snippet
- <Button Height = "150" Width = "120">
- ????<!-- This button has a StackPanel as content. -->
- ????<StackPanel>
- ????????<Ellipse Fill = "Orange" Height = "75" Width = "75"/>
- ????????<TextBlock Text = "OK!" FontSize = "20" HorizontalAlignment = "Center" />
- ????</StackPanel>
- </Button>
The Control parent class defines a number of members that give derived types their core look and feel. Properties exist to establish the control?s opacity, tab order logic, background color, font settings, and so forth. The Control type also provides key infrastructure to apply templates and styles to a UI widget.
FrameworkElement is another key parent class to many UI widgets in that it provides members to control size, tooltips, mouse cursor, and other settings. This class also provides support for animation and data binding services. Here are some common properties of FrameworkElement:
UIElement provides the ability to process mouse and keyboard input. This class also contains properties to control visibility, and geometric transformations. More importantly, this class defines a large number of useful events, shown here:
DependencyObject is the parent that provides derived types the ability to work with the ?dependency property? model. As you might know, a dependency property makes it possible for a property to receive input from multiple locations. This class also provides access to the app?s lower-level event queue via the Dispatcher property.
Beyond this parent, the last stop is System.Object, which I assume needs to introduction ;-)
Happy coding!
679b4b00-f50f-44ca-bbe1-3dd88247790a|1|5.0