0

分離ストレージを使用して Windows Phone 7 アプリケーションを作成したいと考えています。MainPage.xaml と Page1.xaml という名前の 2 つのページを作成しました。MainPage.xaml で、button1 という名前のボタンと textBox1 という名前の textBox を作成しました。Page1.xaml で、listBox1 という名前のリストボックスを作成しました。textBox1 に何かを書き込んで、button1 (MainPage.xaml にあります) をクリックしたときに、すべての内容を表示するには listBox1 が必要です。分離ストレージへ。誰でもこれを手伝ってもらえますか??? ...私はこれに関して非常に多くの場所を調査しました。お疲れ様でした!!!

4

2 に答える 2

0

MainPage.xaml.csでは、次のように記述できます。

Private void button1_click()
{
    NavigationService.Navigate(new Uri("/Page1.xaml?content="+textBox1.Text,UriKind.Relative));
}

Page1.xaml.csでは、次のように記述できます。

using System.Collections.Generic;
using Microsoft.Phone.Controls;
using System.IO;
using System.IO.IsolatedStorage;

namespace PhoneApp1
{
public partial class Page1 : PhoneApplicationPage
{
    public static List<string> list = new List<string>();
    public Page1()
    {
        InitializeComponent();
        listBox1.ItemsSource = list;
        IsolatedStorageFile storge = IsolatedStorageFile.GetUserStoreForApplication();
        StreamWriter writer = new StreamWriter(new IsolatedStorageFileStream("/list.txt", FileMode.OpenOrCreate, storge));
        for (int i = 0; i < list.Count; i++)
        {
            writer.WriteLine(list[i]);
        }   
        writer.Close();
    }

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        if (NavigationContext.QueryString.ContainsKey("content"))
        {
            list.Add(NavigationContext.QueryString["content"]);
        }
        base.OnNavigatedTo(e);
    }
}
}
于 2012-05-12T07:54:07.380 に答える
0

Mainpage.xaml 内

プライベート ボイド button1_click()

{

 string message = textbox1.text;

 NavigationService.Navigate(new Uri(String.format("/Page1.xaml?value1 = {0}",message), UriKind.Relative));}

Page1.Xaml 内

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

{

 base.OnNavigatedTo(e);

 string newparameter = "";

 this.NavigationContext.QueryString.TryGetValue("value1", out newparameter);

 listbox1.items.add(newparameter.ToString());}

次に、新しいパラメータ文字列を取得して isostore に保存します。さらに私に尋ねてください。

于 2012-05-11T11:53:52.380 に答える