Good day!
Most recently, I switched from console programming to forms, or rather trying to write an application on Windows Phone 8. Different nonsense is obtained without difficulty, but if something is more complicated ... In general, that is the question:
There is a form Page1.xaml.cs, on which the elements are located: 4 TextBox and Button1. I decided to add a new Car.cs class to the project with the following content:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PhoneApp1 { public class Car { public string marka; public string model; public int maxspeed; public int horsepower; } } In Page1.xaml.cs, I create an instance of the class:
Car auto = new Car(); And I begin to assign through the usual point "." class fields data from textboxes. There are no problems.
Next, I create a new form / class Page2.xaml.cs, where I have 4 elements of the TextBlock type and the Button2 button. So, the question is: how do I get access to the auto variable, or rather to its fields in the new form? (I want to fill TextBlock'and data from auto when I click on Button2).
Content Page1:
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Navigation; using Microsoft.Phone.Controls; using Microsoft.Phone.Shell; namespace PhoneApp1 { public partial class Page1 : PhoneApplicationPage { public Page1() { InitializeComponent(); } public void Button_Click(object sender, RoutedEventArgs e) { Car auto = new Car(); auto.marka = TextBox_marka.Text; auto.model = TextBox_model.Text; auto.maxspeed = Convert.ToInt32(TextBox_maxspeed.Text); auto.horsepower = Convert.ToInt32(TextBox_horsepower.Text); MessageBox.Show("Информация добавлена успешна!"); } } } Content Page2:
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Navigation; using Microsoft.Phone.Controls; using Microsoft.Phone.Shell; namespace PhoneApp1 { public partial class Page2 : PhoneApplicationPage { public ShowRandomCar() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { *Код кнопки* } } } I just want to say that I am just learning, so please do not shout at me about curved-implemented encapsulation, etc. I just want to understand how to properly establish a connection between the forms.