Why I can't bind to the Dependency Property in my UserControl? I only see the String "Test" as the default value but the binding does not run in a test application. if i do the same binding in the test application in a textblock object than it works. so the problem must be in the myItem class with the dependencyproperty.
Code:
public partial class myItem : UserControl, INotifyPropertyChanged
{
public static DependencyProperty HeaderProperty =
DependencyProperty.Register("Header", typeof(String), typeof(myItem), new UIPropertyMetadata("Test"));
public myItem()
{
InitializeComponent();
DataContext = this;
}
public String Header
{
get
{
return (String)GetValue(HeaderProperty);
}
set
{
SetValue(HeaderProperty, value);
OnPropertyChanged("Header");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}