我有一堂这样写的课
public class AudioPlayer : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
// This method is called by the Set accessor of each property.
// The CallerMemberName attribute that is applied to the optional propertyName
// parameter causes the property name of the caller to be substituted as an argument.
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
[...]
private static AudioPlayer instance = new AudioPlayer();
public static AudioPlayer Instance { get { return instance; } }
private Track currentTrack = null;
// the pointer to the current track selected
// it is useful to retrieve its new position when playlist got updates
public Track CurrentTrack { get { return currentTrack; }
private set
{
currentTrack = value;
NotifyPropertyChanged();
}
}
public class Track : ICloneable
{
public string Title { get; set; }
}
这是xml:
<StackPanel DataContext="{Binding Source={x:Static audiocontroller:AudioPlayer.Instance}}">
<Label Name="lbl_bind" Content="{Binding CurrentTrack.Title}"></Label>
<Button Name="btn" Click="btn_Click" Height="20" ></Button>
</StackPanel>
并且代码有效!
现在我希望使用 ModelView 控制器来组建 AudioPlayer。这个怎么做 ?