Jose John Thottungal
Jose John Thottungal

Reputation: 431

How to bind the value of slider from C# code in windows phone 8.1..?

I want to bind a custom seek bar to the position of media element.

From XAML we can achieve it by

 Value="{Binding ElementName=mediaElement, Path=Position, Mode=TwoWay, Converter={StaticResource FormatConverter}}"

where FormatConverter is a converter class written to convert mediaElement object to slider value during binding.

But I am creating the media element from code, so I want to write C# code to achieve the above. How to do it..?

Upvotes: 0

Views: 359

Answers (1)

Romasz
Romasz

Reputation: 29792

Please take a look at MSDN. I think this should work, if done like this:

 Binding myBind = new Binding() { ElementName = "mediaElement", Path = new PropertyPath("Position"), Converter = this.Resources["FormatConverter"] as IValueConverter, Mode = BindingMode.TwoWay };
 mySlider.SetBinding(Slider.ValueProperty, myBind);

Of course you need to clarify which Resources you use - page's or app's.

Upvotes: 1

Related Questions