3
我想了解当创建附加属性时发生了什么。附加属性冗长
是否需要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); }
}