0

I created a new blank page xaml for windows 8 app. I have a textbox in the main page so the users can type their name in the main page. Also it has a button so that they can open new frame which is the blank page with the following codes :

this.Frame.Navigate(typeof(BlankPage1));

I made a get set class for the textbox so that they can see the value of the textbox in the blank page.

public string t1
    {
        get { return textbox1.Text; }
        set { textbox1.Text = value; }
    }

And these are the codes for the blank page :

protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        MainPage p1 = new MainPage();
        textbox1.Text = p1.t1;
    }

But it won't show the value of the textbox in the blank page. It only shows "TextBox" in the textbox

Ali Vojdanian
  • 2,067
  • 2
  • 31
  • 47
  • 2
    Create a [ViewModel](http://stackoverflow.com/questions/14381402/wpf-programming-methodology/14382137#14382137) instead of trying to manipulate UI elements in code. – Federico Berasategui Feb 01 '13 at 14:56

1 Answers1

2

The problem is that you're creating a new MainPage in the OnNavigatedTo - but you're not actually showing it.

You need to have a reference to the existing instance of MainPage - the one that's visible - not just some arbitrary new instance.

(As an aside, your t1 member is a property - there's no such thing as a "get set class".)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • I show it. I can see the textbox in the blank page. but it won't show me the value of the main page textbox – Ali Vojdanian Feb 01 '13 at 14:56
  • @aliboy38: No, you *don't* show the new instance of `MainPage` that you create in `OnNavigatedTo`. I've edited my answer a little having reread your question, but the fundamental issue is the same. – Jon Skeet Feb 01 '13 at 14:57