I have a base class and another class that inherits from the base. The base class has a DependencyProperty (say "MyDPProperty"):
public int MyDPProperty
{
get { return (int)GetValue(MyDPPropertyProperty); }
set { SetValue(MyDPPropertyProperty, value); }
}
public static readonly DependencyProperty MyDPPropertyProperty =DependencyProperty.Register("MyDPProperty", typeof(int), typeof(ownerclass), new UIPropertyMetadata(0));
in Window's Constructor i wrote:
SomeWpfWindow.DataContext = new ChildClass();
and in my Window's XAML code i have:
<TextBox x:Name="txt"
Text="{Binding Path=MyDPProperty, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
Now, the binding does not work,Although when I bind it in code behind it works :
SomeWpfWindow.txt.SetBinding(TextBox.TextProperty
, new Binding("MyDPProperty")
{
Source = InstanceOfChildClass,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
Mode = BindingMode.TwoWay
});