Reputation: 431
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
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