有两种方法可以访问依赖项属性。行为/反应有什么不同,或者它们的用法相似吗?
第一种方法:
public static DependencyProperty TestProperty =
DependencyProperty.RegisterAttached("Test",
typeof (bool),
typeof (MyBaseClass),
new PropertyMetadata(true));
public static bool GetTest(UIElement element)
{
return (bool) element.GetValue(TestProperty);
}
public static void SetTest(UIElement element, bool value)
{
element.SetValue(TestProperty, value);
}
第二种方法:
public static DependencyProperty TestProperty =
DependencyProperty.Register("Test",
typeof (bool),
typeof (MyBaseClass),
new PropertyMetadata(true));
public bool Test {
get {
return (bool) GetValue(TestProperty);
}
set {
SetValue(TestProperty, value);
}
}