I find this question during code reading. After search MSDN, it has same issue too.
http://msdn.microsoft.com/en-us/library/ms597501.aspx
For DependencyProperty.Register method, it has code example like:
public static readonly DependencyProperty CurrentReadingProperty = DependencyProperty.Register(...);
public double CurrentReading
{
get { return (double)GetValue(CurrentReadingProperty); }
set { SetValue(CurrentReadingProperty, value); }
}
For RegisterAttached method http://msdn.microsoft.com/en-us/library/ms597496.aspx , it has code example like:
public static readonly DependencyProperty IsBubbleSourceProperty = DependencyProperty.RegisterAttached(....);
public static void SetIsBubbleSource(UIElement element, Boolean value)
{
element.SetValue(IsBubbleSourceProperty, value);
}
public static Boolean GetIsBubbleSource(UIElement element)
{
return (Boolean)element.GetValue(IsBubbleSourceProperty);
}
My question is, RegisterAttached doesn’t use property format and use 2 static functions. Why?
This is because RegisterAttached and the associated static methods are for registering attached properties like
Canvas.Left, which are defined in one class, but can be set on instances of any other class (derived from DependencyObject). You can for example setCanvas.Lefton a Button in code like this:You need a static set method since you cannot add a
Leftproperty to class Button.