Windows Phone アプリでアプリを再起動しても、リストボックスの項目を保存するにはどうすればよいですか。私はそれらを何らかの方法でファイルに保存し、次にアプリを起動したときにそれらを読みたいと思っています。助けてください..わかりました私はコードで更新しています:
public partial class MainPage : PhoneApplicationPage { #region VariableDeclaration
DispatcherTimer timer = new DispatcherTimer();
WebClient client = new WebClient();
WebBrowserTask Facebook = new WebBrowserTask();
WebBrowserTask YouTube = new WebBrowserTask();
WebBrowserTask Odnoklassniki = new WebBrowserTask();
WebBrowserTask Vkontakte = new WebBrowserTask();
List<ItemFormat> Items = new List<ItemFormat>();
DispatcherTimer PopulateIsoFile = new DispatcherTimer();
string SongBuffer;
int c = 1;
string Time;
#endregion
#region AppInit
// Constructor
public MainPage()
{
InitializeComponent();
if (Microsoft.Phone.Net.NetworkInformation.DeviceNetworkInformation.IsNetworkAvailable == false)
{
MessageBox.Show("No internet connection", "Error", MessageBoxButton.OKCancel);
}
else
{
if (BackgroundAudioPlayer.Instance.PlayerState == PlayState.Playing)
{
PauseBtn.Visibility = Visibility.Visible;
PlayBtn.Visibility = Visibility.Collapsed;
}
else
{
BackgroundAudioPlayer.Instance.Track = new AudioTrack(new Uri("http://air-online2.hitfm.md/hitfm.mp3"), "HITFM", "Включи себя", null, null);
PlayBtn.Visibility = Visibility.Visible;
PauseBtn.Visibility = Visibility.Collapsed;
}
BackgroundAudioPlayer.Instance.PlayStateChanged += Instance_PlayStateChanged;
SlideView.Begin();
SlideView.Completed += SlideView_Completed;
SlideView.AutoReverse = true;
}
timer.Interval = TimeSpan.FromSeconds(30);
timer.Tick += timer_Tick;
timer.Start();
Loaded += timer_Tick;
}
#region DownloadTrackInfo
void timer_Tick(object sender, EventArgs e)
{
try
{
client.Encoding = System.Text.Encoding.UTF8;
client.Headers[HttpRequestHeader.IfModifiedSince] = DateTime.Now.ToString();
client.DownloadStringAsync(new Uri("http://air-online2.hitfm.md/status_hitfm.xsl"));
client.DownloadStringCompleted += client_DownloadStringCompleted;
}
catch (System.Net.WebException)
{
}
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
string[] raw = e.Result.Substring(166).Split('-');
if (raw[0].Contains(":"))
{
Artist.Text = raw[0].Replace(":", string.Empty).Substring(0, raw[0].Length - 1);
Title.Text = raw[1].Substring(1);
}
else
{
Artist.Text = raw[0];
Title.Text = raw[1].Substring(1);
}
TitleProgress.Visibility = Visibility.Collapsed;
Title.Foreground = new SolidColorBrush(Colors.White);
Artist.Foreground = new SolidColorBrush(Colors.White);
if (DateTime.Now.Minute < 10)
{
Time = "0" + DateTime.Now.Minute.ToString();
}
else
{
Time = DateTime.Now.Minute.ToString();
}
ItemFormat Item = new ItemFormat(e.Result.Substring(166).Replace(":", string.Empty), c, DateTime.Now.Hour.ToString() + ":" + Time);
if ((!(Item.Song == SongBuffer)) || (Recent.Items.Count == 0))
{
Recent.Items.Add(Item);
SongBuffer = Item.Song;
c += 1;
}
}
catch (System.SystemException)
{
}
}
}
public class ItemFormat
{
public string Song { get; set; }
public int Count { get; set; }
public string Time { get; set; }
public ItemFormat(string Song, int count, string time)
{
this.Song = Song;
this.Count = count;
this.Time = time;
}
}
}
このリスト ボックスは、ラジオのプレイリストの一種として使用します。しかし、ユーザーが戻るボタンをクリックしたり、画面がロックされている場合でも、アイテムを保存する必要があります。私の大切なアイテムを救うのを手伝ってください。