I have many pages in my weather app, but I want to get a cityName entered in a TextBlock in the first page and to use it value in the second page. Here are fragments of my code.
Basically I write city name, then push a button and a new page must open using the city name as a parameter.
This is where I call the other page with city name as a parameter:
private void SearchButton_Click(object sender, RoutedEventArgs e)
{
if (Regex.IsMatch(SearchTextBox.Text, @"^\s*$"))
{
//nothing happens
}
else
{
MyFrame.Navigate(typeof(ByCityName), SearchTextBox.Text);
}
}
And in page ByCityName I override the OnNavigatedTo
, City is just a declared string.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string SearchTextBox = e.Parameter.ToString();
var c = new ByCityName();
c.City = SearchTextBox;
this.DataContext = c;
}
And I want to use the SearchTextBox (this is where I write the city name) value in order to call a method with it:
var dataC = await Helper.HelperCityName.GetCityWeather(City);
But the dataC
remains null, and when I debugged it, I noticed that it stops on base.OnNavigatedTo(e)
and e remains null, so from there string SearchTextBox = e.Parameter.ToString();
also remains null.
Can you please help me to resolve this issue?