0

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?

CDspace
  • 2,639
  • 18
  • 30
  • 36
  • Can you use MVVM that I think it may help. – lindexi May 25 '17 at 00:21
  • `Regex.IsMatch(SearchTextBox.Text`, the `SearchTextBox.Text` is null? – lindexi May 25 '17 at 00:22
  • The code you've shared is not complete, there is a lot of things we don't know from your code. But the `Navigate` method is right, `e.Parameter` should not be null. However, it's weird you created a new `ByCityName` in `OnNavigatedTo`. `ByCityName` should be your Page and it should not be instantiated in `OnNavigatedTo` method. Anyway, please share a [mcve] if you still have any problem. – Scavenger May 25 '17 at 08:51

0 Answers0