When Windows Phone 7 uses the system. Threading. thread function to modify the UI element

Source: Internet
Author: User

When Windows Phone 7 uses the system. Threading. thread function to modify the UI element:

           This . Orientationchanged + = New Eventhandler <orientationchangedeventargs> (mainpage_orientationchanged );
System. Threading. Thread a = New System. Threading. Thread ( New Threadstart (initcityandphrase ));
A. Name = " Thread 1 " ;
A. Start ();
Void Initcityandphrase ()
{
Observablecollection <conversationobject> listcity = New Observablecollection <conversationobject> ();
Observablecollection <conversationobject> listphrase = New Observablecollection <conversationobject> ();
Listcity = inboxobject. initiboxobject ();
Listphrase = phrasebook. initphrasebook ();
Dispatcher. begininvoke () =>
{
Citylistbox. itemssource = listcity;
Phraselist. itemssource = listphrase;
});
}

If you do not need dispatcher. begininvoke,ProgramAn invalid thread error is reported during running.

 

In addition, if you use data binding in Windows Phone 7 and then need to modify the data, you need to use the followingCodeAs the binding object:

 
Private String_ Arrow;

Public StringArrow
{
Get
{
Return_ Arrow;
}
Set
{
_ Arrow = value;
Notifypropertychanged ("Arrow");
}
}

If only one member variable and the set and get methods are defined, the UI will not be dynamically updated when the bound object is changed. You need to use the notifypropertychanged method in the code to notify the UI to update the data.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.