Breaking Down the Silverlight UserControl

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
  1. namespace TesterSLApp
  2. {
  3. ????public partial class MainPage : UserControl
  4. ????{
  5. ????????public MainPage()
  6. ????????{
  7. ????????????InitializeComponent();
  8. ????????}
  9. ????}
  10. }

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:

image 

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.

image

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
  1. <Button Height = "150" Width = "120">
  2. ????<!-- This button has a StackPanel as content. -->
  3. ????<StackPanel>
  4. ????????<Ellipse Fill = "Orange" Height = "75" Width = "75"/>
  5. ????????<TextBlock Text = "OK!" FontSize = "20" HorizontalAlignment = "Center" />
  6. ????</StackPanel>
  7. </Button>

image

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.

image

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:

image

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:

image

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!


Posted by: Andrew Troelsen
Posted on: 8/23/2010 at 1:17 PM
Categories: .NET | Silverlight
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Subscribe to this BlogRSS comment feed

Add comment




biuquote
  • Comment
  • Preview
Loading


Contact Us 651-994-8558 1-800-866-9884
Home | Training | Curriculum | Course Finder | Schedule | Enroll | Twin Cities Java User Group | Consulting | Foundation | Jobs | About Us | Our Story | Press Room | Instructors | President | Map & Directions | Sitemap

Java Training | JSF / Struts / Spring / Hibernate Training | Java Power Tools Training | .NET 4.0 & Visual Studio 2010 Training | .NET 3.5 and Visual Studio 2008 Training | .NET 2.0 and Visual Studio 2003 Training | Prism / MVVM / MEF Training | Microsoft Web Development Training | Cloud Computing Training | Ajax / Web Services / XML Training | Groovy and Grails Training | SQL Server 2008 Training | SQL Server 2005 Training | Mobile Development Training | SharePoint 2010 Training | SharePoint 2007 Training | Agile, Process, Analysis & Design Training | Arch/Design Patterns Training | Microsoft Official Curriculum Training | Web Development Training | Ruby Training | Rational Application Developer (RAD) Training | WebSphere Application Server Training | WebSphere Portal Training | WebLogic Training | Boot Camp Training | Project Management Training | C++ Training | Metro / WinRT / Windows 8 Development Training | Retired

Intertech delivers training on-site and virtually serving cities including Phoenix, AZ | San Francisco, CA | Los Angeles, CA | San Diego, CA | San Jose, CA | Washington, DC | Chicago, IL | Orlando, FL | Boston, MA | Duluth, MN | Minneapolis St. Paul, MN | Rochester, MN | Raleigh-Durham, NC | New York, NY | Philadelphia, PA | Austin, TX | Dallas, TX | Houston, TX | Seattle, WA.