0

This code is in my class constructor:

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;

This is in the same class:

public bool AutoScrollingIsEnabled
{
    get
    {
        return !autoScrollingIsPaused;
    }
    set
    {
        autoScrollingIsPaused = !value;
    }
}

But AutoScrollingIsEnabled is never called. What is the problem?

2
  • 2
    Are you implementing INotifyPropertyChanged? Commented Jun 27, 2014 at 18:43
  • I've found that the output window is extremely helpful for binding issues. Commented Jun 27, 2014 at 20:24

1 Answer 1

1

You should be setting Source not Relative source.

autoScrollBinding.Source = this;

But if you want an update from code to get reflected on your window then you'll need to implement INotifyProertyChanged as @evanb mentioned.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.