У меня есть базовый класс и другой класс, который наследуется от базы. Базовый класс имеет DependencyProperty (скажем, "MyDPProperty"):DataBinding не работает с унаследованным DependencyProperty
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));
в конструкторе окна я писал:
SomeWpfWindow.DataContext = new ChildClass();
и в коде XAML моего окна я есть:
<TextBox x:Name="txt"
Text="{Binding Path=MyDPProperty, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
Теперь привязка не работает, хотя, когда я привязываю ее в коде позади, она работает:
SomeWpfWindow.txt.SetBinding(TextBox.TextProperty
, new Binding("MyDPProperty")
{
Source = InstanceOfChildClass,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
Mode = BindingMode.TwoWay
});
Вы можете разместить определение свойства DP? –
Не публикуйте это в комментарии. _Edit_ вопрос. –
Аналогичная проблема здесь: http://stackoverflow.com/questions/6071086/wpf-how-can-i-make-uielement-support-binding –