DependencyProperty.Register method

0 out of 2 rated this helpful - Rate this topic

Registers a dependency property with the specified property name, property type, owner type, and property metadata for the property.

Syntax


public static DependencyProperty Register(
  string name, 
  Type propertyType, 
  Type ownerType, 
  PropertyMetadata typeMetadata
)

Parameters

name

Type: System.String [.NET] | Platform::String [C++]

The name of the dependency property to register.

propertyType

Type: System.Type [.NET] | TypeName [C++]

The type of the property.

ownerType

Type: System.Type [.NET] | TypeName [C++]

The owner type that is registering the dependency property.

typeMetadata

Type: PropertyMetadata

A property metadata instance. This can contain a PropertyChangedCallback implementation reference.

Return value

Type: DependencyProperty

A dependency property identifier that should be used to set the value of a public static read-only field in your class. The identifier is then used both by your own code and any third-party user code to reference the dependency property later, for operations such as setting its value programmatically or attaching a Binding in code.

Remarks

Tip  

If you are programming using a Microsoft .NET language (C# or Microsoft Visual Basic), the TypeName type projects as System.Type. When programming using C#, it is common to use the typeof operator to get references to the System.Type of a type. In Visual Basic, use GetType.

Examples

This example shows a basic usage where a DependencyProperty is established as a public static member of a class. This is done by calling DependencyProperty.Register and storing the return value. For more examples, including a C++/CX example, see Custom dependency properties.


public class Fish : Control
{
    public static readonly DependencyProperty SpeciesProperty =
    DependencyProperty.Register(
    "Species",
    typeof(String),
    typeof(Fish), null
    );
    public string Species
    {
        get { return (string)GetValue(SpeciesProperty); }
        set { SetValue(SpeciesProperty, (string)value); }
    }
}


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Namespace

Windows.UI.Xaml
Windows::UI::Xaml [C++]

Metadata

Windows.winmd

See also

DependencyProperty
Custom dependency properties
Dependency properties overview
XAML user and custom controls sample

 

 

Build date: 1/31/2013

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.