Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Changing binding mode on Slider caused to change value

$
0
0

I have sliders with twoway binding enabled at startup. But when I move them, moving is not smooth enought. So, I decide to change binding mode from twoway to onewaytosource after Thumbs.DragStarted event is called, but this lead to immediate changing value from 1 to 0.

My question is: How to prevent slider from changing its value during new binding if I set OneWayToSource mode?

My code behind is below.

private void SliderCameraZ_OnDragStarted(object sender, DragStartedEventArgs e)
    {
        try
        {
            BindingExpression bindingExpression = ((Slider) sender).GetBindingExpression(Slider.ValueProperty);
            BindingOperations.ClearBinding((Slider) sender, Slider.ValueProperty);
            Binding binding = new Binding();
            binding.Path = bindingExpression.ParentBinding.Path;
            binding.Mode = BindingMode.OneWayToSource;
            binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            ((Slider)sender).SetBinding(Slider.ValueProperty, binding);

        }
        catch (Exception exception)
        {
            MessageBox.Show(exception.Message + exception.StackTrace + exception.TargetSite);
        }
    }


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>