Manually scrolling a ScrollBar on a ScrollViewer RRS feed

  • Question

  • I have the following structure on my page:

    enter image description here

    By default there is a ScrollBar on the ScrollViewer.

    var scrollbars = this.ScrollView.GetDescendantsOfType<ScrollBar>().ToList();
    _scrollBar = scrollbars.FirstOrDefault(x => x.Orientation == Orientation.Horizontal);

    I bind the _scrollBar value to the value of the slider and the maximum to the maximum.

    var valueBinding = new Binding();            
    valueBinding.Source = _scrollBar;
    valueBinding.Mode = BindingMode.TwoWay;
    valueBinding.Path = new PropertyPath("Value");
    BindingOperations.SetBinding(this.Slider, Slider.ValueProperty, valueBinding);
    var maximumBinding = new Binding();
    maximumBinding.Source = _scrollBar;
    maximumBinding.Mode = BindingMode.OneWay;
    maximumBinding.Path = new PropertyPath("Maximum");
    BindingOperations.SetBinding(this.Slider, Slider.MaximumProperty, maximumBinding);

    When I open my page there is a slider and the default scrollbar. When I slide/scroll the scrollViewer both, the slider and scrollbar, are sliding/scrolling synchronously. Now when I'm moving the slider the scrollbar is moving as well but not the scrollViewer. The scrollbar scroll event is also not fired. When I'm moving the scrollbar with the mouse pointer the slider and also the scrollViewer are moving and the scrollbar scroll event is fired.

    What do I need to change that I can move the slider and the scrollViewer is moving synchronously?

    Many thanks

    Thursday, March 6, 2014 2:57 PM