C# 需要在列表框中的另一页中显示一页的内容吗?
我想使用独立存储创建一个windows phone 7应用程序。我创建了两个名为MainPage.xaml和Page1.xaml的页面。在MainPage.xaml中,我创建了一个名为button1的按钮和一个名为textBox1的文本框。在Page1.xaml中,我创建了一个名为listBox1的列表框。如果我在textBox1中写入了一些内容,当我单击按钮1(位于MainPage.xaml中)时,我需要listBox1显示所有内容,无论我写入textBox1的内容是什么,我还需要将listBox1中的内容保存到独立的存储中。有人能帮我吗?…我研究过很多地方。提前感谢您的辛勤工作 在Mainpage.xaml中 专用无效按钮1\u单击() { 在Page1.Xaml中 受保护的覆盖无效OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) {C# 需要在列表框中的另一页中显示一页的内容吗?,c#,windows-phone-7,C#,Windows Phone 7,我想使用独立存储创建一个windows phone 7应用程序。我创建了两个名为MainPage.xaml和Page1.xaml的页面。在MainPage.xaml中,我创建了一个名为button1的按钮和一个名为textBox1的文本框。在Page1.xaml中,我创建了一个名为listBox1的列表框。如果我在textBox1中写入了一些内容,当我单击按钮1(位于MainPage.xaml中)时,我需要listBox1显示所有内容,无论我写入textBox1的内容是什么,我还需要将listB
然后获取新参数字符串并将其保存在isostore中。如果需要进一步帮助,请询问我。在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);
}
}
}
使用System.Collections.Generic;
使用Microsoft.Phone.Controls;
使用System.IO;
使用System.IO.IsolatedStorage;
命名空间PhoneApp1
{
公共部分类第1页:PhoneApplicationPage
{
公共静态列表=新列表();
公共页1()
{
初始化组件();
listBox1.ItemsSource=列表;
IsolatedStorageFile storge=IsolatedStorageFile.GetUserStoreForApplication();
StreamWriter writer=newstreamwriter(new-IsolatedStorageFileStream(“/list.txt”,FileMode.OpenOrCreate,storge));
for(int i=0;i
出现错误-未处理NullReferenceException突出显示---->listbox1.items.add(newparameter.ToString());}需要帮助SENTHIL KUMAR…除了ListBox而不是TextBox之外,这与您在此处发布的帖子有何区别:
Private void button1_click()
{
NavigationService.Navigate(new Uri("/Page1.xaml?content="+textBox1.Text,UriKind.Relative));
}
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);
}
}
}