4
I tried to follow that method, but there is an error in Mainpage, saying that the NavigationService
does not exist in the current context.
In Blankpage, the same error occurs in NavigationContext
.
How can I fix this? Need to import some library, as it is on Android?
From what I understand, this method is to send strings
. How to send type variables int
and double
?
Follows the code:
Mainpage.xaml:
<Grid>
<TextBlock x:Name="helloMessage" Margin="10,132,10,0" TextWrapping="Wrap" Text="Hello" VerticalAlignment="Top" FontSize="26.667" FontFamily="Segoe UI Light"/>
<Button x:Name="sayHelloButton" Content="Say Hello!" HorizontalAlignment="Stretch" Margin="10,64,10,0" VerticalAlignment="Top" Click="sayHelloButton_Click"/>
<TextBox x:Name="nameField" Margin="10,10,10,0" TextWrapping="Wrap" Text="Enter your name..." VerticalAlignment="Top" Height="39"/>
<Button x:Name="button_GoToPage" Content="Go to page" HorizontalAlignment="Right" Margin="0,159,10,0" VerticalAlignment="Top" Click="button_GoToPage_Click"/>
</Grid>
Mainpage.xaml.Cs:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace MyApp
{
public sealed partial class MainPage : Page
{
string texto1 = "Hello World!";
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void sayHelloButton_Click(object sender, RoutedEventArgs e)
{
helloMessage.Text = "Hello, "+nameField.Text+"!";
}
private void button_GoToPage_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/BlankPage.xaml?msg=" + nameField.Text, UriKind.Relative));
; }
}
}
Blankpage.xaml:
<Page
x:Class="MyApp.BlankPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<AppBarButton x:Name="appBarButton" HorizontalAlignment="Left" Icon="Back" Label="" Margin="-10,-2,0,0" VerticalAlignment="Top" Click="appBarButton_Click"/>
<TextBlock x:Name="textName1" Margin="10,98,10,492" TextWrapping="Wrap" Text="(vazio)" FontSize="32" HorizontalAlignment="Center"/>
</Grid>
Blankpage.xaml.Cs:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace MyApp
{
public sealed partial class BlankPage : Page
{
public BlankPage()
{
this.InitializeComponent();
/// Manter página armazenada em cache, mesmo utilizando o botão voltar
this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string msg = "";
if (NavigationContext.QueryString.TryGetValue("msg", out msg))
textName1.Text = msg;
}
private void appBarButton_Click(object sender, RoutedEventArgs e)
{
Frame.GoBack();
}
}
}
Visual Studio presents this error: "The name "Isolatedstoragesettings" does not exist in the current context."
– EdeiltonSO
@Edeiltonso, it must be because your application is not marked as an application "Windows Phone Silverlight". I will edit my reply.
– Dherik
Thank you very much, the first method worked perfectly! D
– EdeiltonSO