我的 Windows Phone 项目中的绑定有问题。我将一个类绑定到一个滑块,但它不会更新值。如果我第一次启动应用程序,则绑定连接已正确建立,并且滑块确实具有正确的值。但是,如果我更改“位置”或“持续时间”值,滑块将不会随之更新。
你能帮我么?我没有任何线索,我做错了什么:(
类.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>
...