Answer the question
In order to leave comments, you need to log in
How to pass a variable to another WPF page?
Good afternoon. Ran into a new stupid question. How can you pass a variable from one XAML page to another?
Both pages were created using Visual Studio.
Page1
Page2.
You need to pass the PreID variable.
I go from the first to the second page like this:
private void pre1_Click(object sender, RoutedEventArgs e)
{
this.Content = new Page2();
}
Answer the question
In order to leave comments, you need to log in
A very bad option is through the constructor.
private void pre1_Click(object sender, RoutedEventArgs e)
{
this.Content = new Page2("переменная");
}
private void pre1_Click(object sender, RoutedEventArgs e)
{
var page = new Page2();
page.Variable = "переменная";
this.Content = page;
}
private void pre1_Click(object sender, RoutedEventArgs e)
{
_service.Variable = "переменная";
this.Content = new Page2();
}
var service = _container.Resolve<IMyService>;
Title = service.Variable;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question