我想要构建一个wp7控件,所以我写它并且一切顺利,但问题是我可以拦截写(请参阅onItemsSourcePropertyChanged)但不读取我想更好地解释:
public static readonly
DependencyProperty ItemsSourceProperty=
DependencyProperty.Register(
"ItemsSource",
typeof(ObservableCollection<ObjWithDesc>),
typeof(HorizontalListBox),
new PropertyMetadata(OnItemsSourcePropertyChanged)
);
static void OnItemsSourcePropertyChanged(DependencyObject obj,DependencyPropertyChangedEventArgs e)
{
((HorizontalListBox) obj).OnItemsSourcePropertyChanged(e);
}
当我使用SetValue(dp,..)但是没有onItemsSourcePropertyRead时会调用OnItemsSourcePropertyChanged?当我使用GetValue()时调用?感谢
答案 0 :(得分:0)
您可以将OnRead操作添加到支持字段的getter中:
public string ItemsSource
{
get
{
// Call your OnRead functionality here!
return (string)GetValue(ItemsSourceProperty);
}
set
{
SetValue(ItemsSourceProperty, value);
}
}