I have made an application with a NavigationWindow with a page loaded in it. Also is another (normal) window in this project.
The names of these windows/pages:
NavigationWindows: MainWindows
Page: Page1
Window: TwitterConnect
Label on Page: label4
I have a label on my Page1 and I want to change it from TwitterConnect.
Because I make a new instance of Page1 to call method ConnectToTwitter(), the label on my page doesn’t update.
Here is the code in de codebehind of TwitterConnect:
private void button1_Click(object sender, RoutedEventArgs e)
{
string pin = twitpin.Text;
Page1 page = new Page1();
page.ConnectToTwitter(pin, genratedToken);
this.Close();
}
I searched google to find a solution, but I don’t get it.
I think it has something to do with Dispatcher?!
I’m really a beginner in C#, VS10express and WPF.
How can I change label4 from TwitterConnect?
Can you please explain it with a snippet of code?
You are creating a new instance of Page1.xaml from the TwitterConnect window. What you need to do is find a way to access the current instance of Page1.xaml which can easily be acheived by using the DataContext property of the Window class.
Page1.xaml.cs
TwitterConnect.xaml.cs
If I’ve missed anything out please let me know. Also, I strongly advise against this configuration as it could become a nightmare to maintain. A better approach might be to add a method or property onto Page1.cs to handle setting the text on label4.