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

Binding can not be changed after it has been used in wpf

$
0
0

Hi,

I have one textbox and slider control. 

Binding is done two way.

 <TextBox Height="23" HorizontalAlignment="Left" Margin="75,33,0,0" Name="tbrs" VerticalAlignment="Top" Width="48" Text="{Binding ElementName=sliderrs, Path= Value,UpdateSourceTrigger=PropertyChanged}" />

<Slider Height="23" Margin="0,35,46,0" Name="sliderrs" VerticalAlignment="Top" Minimum="15" Maximum="95"  IsEnabled="True" TickPlacement="TopLeft" MinWidth="5" SmallChange="1" LargeChange="5" Value="{Binding Path=Rs, UpdateSourceTrigger=PropertyChanged, Mode=Twoway}" TickFrequency="10" HorizontalAlignment="Right" Width="110"/>

This part is called on basis of check box checked and uncheked:

Binding rsBind = BindingOperations.GetBinding(this.control.sliderrs, Slider.ValueProperty);

  Binding rstbBind = BindingOperations.GetBinding(this.control.tbrs, TextBox.TextProperty);

 BindingOperations.SetBinding(this.control.sliderrs, Slider.ValueProperty, rsBind );
  BindingOperations.SetBinding(this.control.tbrs, TextBox.TextProperty, rsobBind);

when I'm move slider control to some value let's say 15 to 20 on that time getting this error "Binding can not be changed after it has been used".

After this I have googled and some guys has suggested to create new binding object. so I have done like this:

Binding rsBindnew = new Binding("Rs");
 rsBindnew.Source = rsBind.Source;
 rsBindnew.Path = rsBind.Path;

BindingOperations.SetBinding(this.control.sliderrs, Slider.ValueProperty, rsBindnew);

after this I'm not getting any error but there is two problem:

1. When I move slider control some value like 15 to 20 It's not updating the latest value towards  dll side I mean rs value.

2. When I'm doing uncheck to checkbox It's setting their default value,It's not keeping latest value.

P.S: During uncheck to checkbox I'm setting UpdateSourceTrigger to Explicit. It's working fine when I have changed some value from dll side like rs value 15 to 20. showing correct value on UI side.

Please help it's very urgent for me.


vikas sharma AB


Viewing all articles
Browse latest Browse all 18858

Trending Articles



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