Printer Friendly Version      Send     
Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight
UserControl Class
Other versions are also available for the following:
.NET Framework Class Library for Silverlight
UserControl Class
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Provides the base class for defining a new control that encapsulates related existing controls and provides its own logic.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

Visual Basic (Declaration)
<ContentPropertyAttribute("Content", True)> _
Public Class UserControl _
    Inherits Control
Visual Basic (Usage)
Dim instance As UserControl
C#
[ContentPropertyAttribute("Content", true)]
public class UserControl : Control
Visual C++
[ContentPropertyAttribute(L"Content", true)]
public ref class UserControl : public Control
JScript
public class UserControl extends Control
XAML Object Element Usage
<UserControl ...>
  singleContentElement
</UserControl>
-or-
<UserControl .../>
XAML Values
singleContentElement

Exactly one object element for a class that derives from UIElement. This is almost always an object that can take child elements (such as a Panel) so that multiple elements can be added to content. XAML processing of a UserControl has a special behavior that sets this content to the otherwise protected Content property.

When you create a Silverlight project in Microsoft Visual Studio 2008, the new project creates a class that inherits from UserControl. The UserControl is a logical choice as the base class for a Silverlight-based application because the UserControl meets all the requirements necessary.

Two other primary reasons for creating a control that inherits from UserControl are 1) to separate functionality into smaller, manageable pieces of logic that can be created independently from an application and other controls; 2) to group related controls that can be used more than once in an application.

A UserControl is a composite of existing elements. You add elements to a UserControl by setting the Content property. Since Content is a single UIElement, you typically set it to an element that inherits from the Panel class and populate the Children of the Panel. The Content property is protected so that developers who use your control cannot change its purpose.

It is typical to put a UserControl inside of another UserControl. When you create a UserControl that encapsulates a piece of logic, you will usually place that UserControl as the root element of your Silverlight-based application, which is another UserControl.

Although the UserControl inherits the template property from the Control class, you cannot apply a ControlTemplate to a UserControl. To create a control that uses a ControlTemplate, see Creating a Templatable Control.

System..::.Object
  System.Windows..::.DependencyObject
    System.Windows..::.UIElement
      System.Windows..::.FrameworkElement
        System.Windows.Controls..::.Control
          System.Windows.Controls..::.UserControl
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker