0
votes

Sorry if title is weird , because the problem itself is kinda weird.

I have a TextBlock and Slider Control on Clientside.

The Slider is {Binding} to Textblock.

This is the code for them -

 <TextBlock Text="{Binding Value}" x:Name="Name1Value" FontSize="25"/>
  <Slider   ValueChanged="slider_ValueChanged_1"  x:Name="slidervalve"  Value= "{Binding ElementName=Name1Value,Path=Text}"  StepFrequency="25"   />

Now when Slider Value changes,Slider calls a method slider_ValueChanged_1,which sends its value to server. The server accepts the value and sends the new value back to client and this new value from server is set to the textblock( x:Name="Name1Value") through an observablecollection with inotifypropertychanged implemented. The slider is {Binding} to textblock.

1)Now the first time i change the value on slider on client, the server accepts the new value and returns the new value and i am setting the new value to textblock. 2)Now i am changing the value on server and the value is correctly updated in textblock and then the slider value changes to textblock value.

3) now after this first cycle,if i change the value on server again ,the textblock on client is getting updated but the slider does not change to textblock value.

But the slider is bound to textblock. How can i solve this?

Edit1: FYI , the textblock and the slider are in same page but in different stackpanels

1
This seems very confusing, if not recursive, what's the actual goal of the user experience here. It sounds like you want to use a slider to set a value but override that value through a value set on the server? So if I change the slider, I'm not going to see the slider where I left it, but it will be reset for me based on something the server has returned (well, assuming what you are trying to wire together works?) I'm not sure I see why you are using element binding in this case then? - Jim O'Neil
@JimO'Neil When user at client side changes the slider ,the slider updates momentarily and then waits for server to accept the slider's new value . When the server accepts the value the textblock is updated and the slider(which binds to textblock) keeps its new position. But after first recursion ,the textblock still gets updated fine ,but the slider stops updating to textblock's value even though its {Binding} .The business case here being that when user changes the slider value the server should accept the new value .Otherwise the slider goes back to its previous location. - raghu_3

1 Answers

0
votes

A Slider control's Value property is of type double, while TextBlock.Text is a string. Binding these two together without a converter is asking for trouble. You should bind your Slider.Value to the DataContext/view model and typically make sure the binding Mode=TwoWay.