Code in my MainPage.xaml
<TextBox x:Name="txtBox1" HorizontalAlignment="Left"
Margin="376,350,0,0" TextWrapping="Wrap"
VerticalAlignment="Top" Height="14" Width="113"
Text="{Binding TextBox1Text}"/>
Code in my MainPage.xaml.cs
public string TextBox1Text
{
get { return this.txtBox1.Text; }
set { this.txtBox1.Text = value; }
}
Code in my Page2.xaml
MainPage main = new MainPage();
protected override void OnNavigatedTo(NavigationEventArgs e)
{
txtBlock1.Text = main.TextBox1Text;
}
when i run this there no text that output in my textblock
You are creating a new instance of
MainPage
.TextBox1Text
isn't initialized with a value.If you want it to be a value shared across all of your pages either create a static class or declare your property in the App.cs file
This would be the same as saying.
x.StringProperty
isn't set now.A simpler way to do that is to pass parameters between pages:
MainPage.xaml.cs
:And in
Page2.xaml.cs
:Edit: It appears that you want to pass multiple parameters. You can package multiple objects in a
List<T>
collection or create a class:In your current page:
In
MultiGame.cs
you can "unpack" the items from the class: