我正在使用 IsolatedStorage 与音频代理进行通信,如下所示:
在我的每个页面中:
private void playButton_Click(object sender, RoutedEventArgs e)
{
if (PlayState.Playing == BackgroundAudioPlayer.Instance.PlayerState)
{
BackgroundAudioPlayer.Instance.Pause();
}
else
{
IsolatedStorageSettings.ApplicationSettings["BtnClicked"] = "1"; (or 2 or 3)
IsolatedStorageSettings.ApplicationSettings.Save();
BackgroundAudioPlayer.Instance.Stop();
BackgroundAudioPlayer.Instance.Play();
}
}
在我的 AudioPlayer.cs 中:
`case UserAction.Play:
if ((string)IsolatedStorageSettings.ApplicationSettings["BtnClicked"] == "1")
{
_playList = _playList1;
}
else if ((string)IsolatedStorageSettings.ApplicationSettings["BtnClicked"] == "2")
{
_playList = _playList;
}
else if ((string)IsolatedStorageSettings.ApplicationSettings["BtnClicked"] == "3")
{
_playList = _playList2;
}
PlayTrack(player); `
然而,问题是“_playlist”变量除了第一次之外没有被更新。例如,如果我打开第 1 页,它会正确选择 _playlist1,但如果我按“返回”然后进入第 2 页,它仍然会选择 _Playlist1。每次在我的应用程序中选择新页面时,如何强制更新变量?其余代码也非常类似于:http: //msdn.microsoft.com/en-us/library/windowsphone/develop/hh202978%28v=vs.105%29.aspx