【发布时间】:2012-02-18 15:51:19
【问题描述】:
我有一个带有DataContext="{Binding RelativeSource={RelativeSource self}}" 的自定义用户控件
在后面的代码中,我创建了一个依赖属性,例如:
public static DependencyProperty ElementNameProperty = DependencyProperty.Register("ElementName",
typeof(string),
typeof(ElementControl),
new PropertyMetadata(new PropertyChangedCallback((s, e) => { new Base().OnPropertyChanged("ElementName"); })));
public string ElementName
{
get
{
return (string)base.GetValue(ElementNameProperty);
}
set
{
base.SetValue(ElementNameProperty, value);
}
}
现在,当我尝试在我的 mainpage.xaml 中使用此用户控件并使用以下绑定:<test.TestControl ElementName="{Binding name}" /> 时,它一直在我的自定义用户控件中搜索“名称”属性,而不是它应该来自哪里?
我做错了什么?
【问题讨论】:
标签: c# silverlight binding custom-controls dependency-properties