相关文章推荐
酷酷的火龙果  ·  Android ...·  3 周前    · 
笑点低的荒野  ·  vue3中unplugin-auto-imp ...·  1 年前    · 
逃跑的高山  ·  c++ - What does new ...·  1 年前    · 

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft Edge More info about Internet Explorer and Microsoft Edge
 static DependencyProperty RegisterAttached(winrt::hstring const& name, TypeName const& propertyType, TypeName const& ownerType, PropertyMetadata const& defaultMetadata);
public static DependencyProperty RegisterAttached(string name, System.Type propertyType, System.Type ownerType, PropertyMetadata defaultMetadata);
function registerAttached(name, propertyType, ownerType, defaultMetadata)
Public Shared Function RegisterAttached (name As String, propertyType As Type, ownerType As Type, defaultMetadata As PropertyMetadata) As DependencyProperty

Parameters

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

Returns

Examples

This example defines a class that derives from DependencyObject , and defines an attached property along with the identifier field. The scenario for this class is that it is a service class that declares an attached property that other UI elements can set in XAML, and the service potentially acts on the attached property values on those UI elements at run time. For more examples, see Custom attached properties .

public abstract class AquariumServices : DependencyObject
    public enum Buoyancy {Floats,Sinks,Drifts}
    public static readonly DependencyProperty BuoyancyProperty = DependencyProperty.RegisterAttached(
      "Buoyancy",
      typeof(Buoyancy),
      typeof(AquariumServices),
      new PropertyMetadata(Buoyancy.Floats)
    public static void SetBuoyancy(DependencyObject element, Buoyancy value)
        element.SetValue(BuoyancyProperty, value);
    public static Buoyancy GetBuoyancy(DependencyObject element)
        return (Buoyancy)element.GetValue(BuoyancyProperty);
Public Class AquariumServices
    Inherits DependencyObject
    Public Enum Buoyancy
        Floats
        Sinks
        Drifts
    End Enum
    Public Shared ReadOnly BuoyancyProperty As DependencyProperty = _
          DependencyProperty.RegisterAttached(
          "Buoyancy", _
          GetType(Buoyancy), _
          GetType(AquariumServices), _
          New PropertyMetadata(Buoyancy.Floats))
    Public Sub SetBuoyancy(element As DependencyObject, value As Buoyancy)
        element.SetValue(BuoyancyProperty, value)
    End Sub
    Public Function GetBuoyancy(element As DependencyObject) As Buoyancy
        GetBuoyancy = CType(element.GetValue(BuoyancyProperty), Buoyancy)
    End Function
End Class