Wpf 附加属性详细性
我试图理解创建附加属性时发生的一切 是否需要Wpf 附加属性详细性,wpf,silverlight,dependency-properties,Wpf,Silverlight,Dependency Properties,我试图理解创建附加属性时发生的一切 是否需要SetText()和GetText()方法(通过代码段/模板插入,我在许多示例中都看到了这些方法)?框架内有什么在使用它们 public static readonly DependencyProperty TextProperty = DependencyProperty.RegisterAttached("Text", typeof(string),
SetText()
和GetText()
方法(通过代码段/模板插入,我在许多示例中都看到了这些方法)?框架内有什么在使用它们
public static readonly DependencyProperty TextProperty =
DependencyProperty.RegisterAttached("Text",
typeof(string),
typeof(FundIndexDataHeaderItem),
new PropertyMetadata(default(string)));
public static void SetText(UIElement element, string value)
{
element.SetValue(TextProperty, value);
}
public static string GetText(UIElement element)
{
return (string)element.GetValue(TextProperty);
}
我是否可以用一个简单的属性替换这些方法,这样我就可以通过属性而不是使用这些方法来获取/设置
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
它们只是为了方便您,框架不使用它们 您不能执行后一种操作,因为您需要以某种方式传递设置了该属性的实例,因为该属性是附加的,您没有将该实例作为
this