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.