I have the following in xaml.
<TextBlock Text="{Binding Title}" />开发者_如何转开发
And created the following dependency property,
public string Title
{
get { return (string)GetValue(TitleProperty); }
set
{
SetValue(TitleProperty, value);
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Title"));
}
}
}
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register("Title", typeof(string), typeof(ColumnChart), new PropertyMetadata(string.Empty));
Now if I bind the Title property in other xaml, the value is not taken. Because the PropertyChange notification is not called. And always PropertyChanged is null.
How I can notify to the list of observers that this property is changed, so that the value will be updated.
I'm not quite sure what you mean by "How I can notify to the list of observers that this property is changed, so that the value will be updated."
This looks like a user control, as it's not typical to use dependency properties in view models. Therefore, have a look at Routed Events. The Register() method for a dependency property has an override which will take a handler which will be invoked when the property changes. You can invoke a custom routed event from within this handler. Consumers of your user control can subscribe to this routed event using the standard mechanisms.
精彩评论