【发布时间】:2011-11-29 21:40:33
【问题描述】:
我试图了解创建附加属性时发生的一切。
是否需要 SetText() 和 GetText() 方法(通过 sn-p/template 插入并且我在许多示例中看到)?框架内的什么在使用它们?
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); }
}
【问题讨论】:
标签: wpf silverlight dependency-properties