I’ve got a problem with a binding in my windows phone project. I’m binding an class to a slider, but it won’t update the value. If I first start the app, the binding connection is established correctly and the slider does have its correct value. But if I change the “position” or “duration” value, the slider won’t update with it.
Can you please help me? I don’t have any clue, what I’m doing wrong 🙁
Class.cs:
public class Status : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void PropChanged(string propName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
public double duration
{
get { return _duration; }
set
{
if (this._duration == value)
return;
_duration = value;
PropChanged("duration");
}
}
public double position
{
get { return _position; }
set
{
if (this._position == value)
return;
_position = value;
PropChanged("position");
}
}
}
MainPage.xaml.cs:
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
this.ContentPanel.DataContext = _Status;
}
}
MainPage.xaml:
...
<Grid x:Name="ContentPanel" Margin="12,12,12,0" Grid.RowSpan="2">
<Slider x:Name="sl_PlayBackProgress"
Value="{Binding Path=position}"
Maximum="{Binding Path=duration}"
Height="91"
HorizontalAlignment="Left"
Margin="0,40,0,0"
VerticalAlignment="Top"
Width="408"/>
</Grid>
...
Don’t know if it different from normal XAML/WPF. But in normal case I would recommend first to set up Binding.Mode to TwoWay and next just break on position.set entrance – and see the passed
value