SevenDays
SevenDays

Reputation: 3768

Changing text of textblock from another page

Messages.xaml

<TextBlock  x:Name="txt_count_unreads" Text="0"  />

App.xaml check messages...and

Messages mm = new Messages();

 Messages.txt_count_unreads.Text = unreads.ToString();

But text not changing?What's wrong?

Upvotes: 1

Views: 1081

Answers (1)

Praetorian
Praetorian

Reputation: 109089

Each XAML page, along with its code behind page, are a class, having the same name as the XAML file. On Windows Phone 7 all such page classes have the common base class PhoneApplicationPage. When you navigate to a new page, the phone framework creates an instance of that class and loads it into the PhoneApplicationFrame.

So, creating an instance of your page class randomly somewhere in your code, and changing properties on that instance, will not work!

You should make the unreads property available to the Messages class (or pass it in the query string while navigating to the Messages page) and then set the TextBlock text within the Messages constructor.


This is really basic stuff you need to know before ever starting to write code for a phone app. I'm not trying to discourage you, but you will benefit a great deal if you spend a day or two reading a book. Charles Petzold has a free book that starts of with very basic applications and moves on to more advanced topics.

Upvotes: 5

Related Questions