C# 要在另一个页面中显示某个页面的结果吗?

C# 要在另一个页面中显示某个页面的结果吗?,c#,windows-phone-7,C#,Windows Phone 7,我已经使用独立存储创建了一个WindowsPhone7应用程序。在这个应用程序中,我使用了一个名为btnRead的按钮、一个名为txtRead的文本块和一个名为txtwite的文本框。如果我在文本框(txtwite)中写入内容并单击按钮(btnRead)。然后textblock(txtRead)显示或保存我在textbox上写的任何内容(所有这些都是在单个MainPage.xaml中创建的)。现在我已经创建了另一个page1.xaml并创建了一个名为txtShow的文本块。但是我希望文本块(tx

我已经使用独立存储创建了一个WindowsPhone7应用程序。在这个应用程序中,我使用了一个名为btnRead的按钮、一个名为txtRead的文本块和一个名为txtwite的文本框。如果我在文本框(txtwite)中写入内容并单击按钮(btnRead)。然后textblock(txtRead)显示或保存我在textbox上写的任何内容(所有这些都是在单个MainPage.xaml中创建的)。现在我已经创建了另一个page1.xaml并创建了一个名为txtShow的文本块。但是我希望文本块(txtShow)显示我在MainPage.xaml中的textbox上写的所有内容。我还上传了我的项目-

下面是我使用过的MainPage.xaml.cs源代码-:

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
        myStore.CreateDirectory("Bookmark");

        using (var isoFileStream = new IsolatedStorageFileStream("Bookmark\\myFile.txt", FileMode.OpenOrCreate, myStore))
        {
            //Write the data
            using (var isoFileWriter = new StreamWriter(isoFileStream))
            {
                isoFileWriter.WriteLine(txtWrite.Text);
            }
        }

        try
        {
            // Specify the file path and options.
            using (var isoFileStream = new IsolatedStorageFileStream("Bookmark\\myFile.txt", FileMode.Open, myStore))
            {
                // Read the data.
                using (var isoFileReader = new StreamReader(isoFileStream))
                {
                    txtRead.Text = isoFileReader.ReadLine();
                }
            }
        }
        catch
        {
            // Handle the case when the user attempts to click the Read button first.
            txtRead.Text = "Need to create directory and the file first.";
        }
    }

如果您在同一页面的文本块中显示文本框中的文本,那么通过绑定将更容易做到这一点

<TextBox x:Name="txtWrite"/>
<TextBlock  Text="{Binding Text, ElementName=txtWrite}"/>

如果您喜欢使用IsoStorage,可以像上面在OnNavigatedTo方法中那样执行读取操作。

然后将其添加到列表框:ListBox.Items.add(text);
    // Navigate to Page1 FROM MainPage 
    // This can be done in a button click event
    NavigationService.Navigate(new Uri("/Page1.xaml?text=" + txtWrite.Text, UriKind.Relative));

// Override OnNavigatedTo in Page1.xaml.cs
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    string text;
    NavigationContext.QueryString.TryGetValue("text", out text);
    txtRead.Text = text;
}