Reputation: 153
I dont know how to begin, so i just start with a screenshot and the code of it:
MainPage.xaml
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="48"/>
</Grid.RowDefinitions>
<Frame x:Name="MainContent"/>
<Grid Grid.Row="1" Background="Gray">
<TextBlock x:Name="ResultTB"
VerticalAlignment="Center"
Text="Should also be here"
HorizontalAlignment="Center"/>
</Grid>
</Grid>
MainPage.xaml.cs
public MainPage()
{
InitializeComponent();
MainContent.Navigate(typeof(ContentFrame));
}
ContentFrame.xaml
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBox x:Name="Input"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Width="200"/>
</Grid>
Now i want to grad ResultTB the text of Input. What is the simplest and best way to do this?
Upvotes: 3
Views: 1625
Reputation: 948
For anyone looking for this in the future - a little similar answer to Alexej but simpler: For Example, lets say I want to change text of object "SomeObject" (x:Name = "SomeObject") which is in MainPage:
MainPage mainFrame = (MainPage)((Frame)Window.Current.Content).Content;
mainFrame.SomeObject = "my text";
Upvotes: 1
Reputation: 2679
You can use override of Navigate method: Frame.Navigate(TypeName, Object)
Where Object is parameter. You can get in another page in OnNavigatedTo event. Something like:
string txt=ResultTB.Text;
MainContent.Navigate(typeof(ContentFrame), txt);
and on another page add OnNavigatedTo event and inside:
var parameter = e.Parameter as string;
Upvotes: 0