In my wpf application, I have window 1, window 2, and a separate class file called share.cs with a public integer variable 'a'
I have a textbox and a button in each of the windows.
on the button in window1, i perform the following operation
Window1.cs
private void button1_Click(object sender, RoutedEventArgs e)
{
share s = new share();
s.a = Convert.ToInt32(textBox1.Text);
Window2 win = new Window2();
win.Show();
}
Basically, i just want to copy the value from textbox on window1 into the variable in share class, and then display the window2.
Now, In window2, I would like to retrieve the value from variable 'a' in share class and would like to display it on the textbox in window2, when i click on the button in window2. AND it is my understanding that the instance 's' in window1 is different from that of window2, and that is the reason why i am not getting the output correctly.
Window2.cs
private void button1_Click(object sender, RoutedEventArgs e)
{
share s = new share();
textBox1.Text = Convert.ToString(s.a);
}
Is there anyway, that I could create a single common instance and use it in both the classes ? If so, where should I create the instance and make it available to both the windows ? i just want both the windows to use the variable 'a' in share class using same instance.
This is what I have in share.cs.
public class share
{
public int a;
}
I am a learner and I need direct answers please; not suggestions. Any help would be truly appreciated. Thanks. :)