Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 附加属性详细性_Wpf_Silverlight_Dependency Properties - Fatal编程技术网

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