V
V
Valery Kirichenko2014-05-05 16:22:10
WPF
Valery Kirichenko, 2014-05-05 16:22:10

WPF Accessing objects of another page

There are two pages - Page1.xaml and Page2.xaml. Some variable is defined in Page2
public string variable{ get; set; }
How can I set this variable from Page1?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sumor, 2014-05-05
@valera5505

It is not obvious from the question how Page1 and Page2 are connected.
If Page1 is called from Page2, then the easiest way to call is to create an instance of Page2 and assign a value to a variable.
Can be used to pass a transition state object, an optional parameter to the Navigate method. Example from MSDN:

void goButton_Click(object sender, RoutedEventArgs e)
{
    this.NavigationService.Navigate(new ContentPage(), DateTime.Now);
}
void NavigationService_LoadCompleted(object sender, NavigationEventArgs e)
{
    DateTime requestDateTime = (DateTime)e.ExtraData;
    string msg = string.Format("Request started {0}\nRequest completed {1}", requestDateTime, DateTime.Now);
    MessageBox.Show(msg);
}

Well, the most unrecommended way is to use static properties to transfer state.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question