这段代码在我的类构造函数中:
CheckBox autoScrollCheckBox = new CheckBox();
autoScrollCheckBox.VerticalAlignment = VerticalAlignment.Center;
autoScrollCheckBox.Content = "Enable";
Binding autoScrollBinding = new Binding();
autoScrollBinding.Path = new PropertyPath("AutoScrollingIsEnabled");
autoScrollBinding.RelativeSource = new RelativeSource(RelativeSourceMode.Self);
autoScrollBinding.Mode = BindingMode.TwoWay;
autoScrollCheckBox.SetBinding(CheckBox.IsCheckedProperty, autoScrollBinding);
autoScrollBox.Content = autoScrollCheckBox;
这是同一类:
public bool AutoScrollingIsEnabled
{
get
{
return !autoScrollingIsPaused;
}
set
{
autoScrollingIsPaused = !value;
}
}
但从未调用过AutoScrollingIsEnabled。有什么问题?
答案 0 :(得分:1)
您应该设置Source而不是相对来源。
autoScrollBinding.Source = this;
但是如果你想要从代码中获得更新以反映在你的窗口上,那么你需要实现INotifyProertyChanged作为@evanb提到。