4. Silverlight中所有的数据操作都是异步的,下面的代码其实是不能工作的:
MyOldWebService srv = new MyOldWebService();
string strReturn = srv.GetSomeValue();
txtValue.Text = strReturn;
string strReturn = srv.GetSomeValue();
txtValue.Text = strReturn;
我们可以通过调用WCF服务来解决这个问题(比如在Page的InitializeComponent方法之后来调用):
public MainPage()
{
InitializeComponent();
Service1Client client = new Service1Client();
client.DoWorkCompleted += new EventHandler<DoWorkCompletedEventArgs>
(client_DoWorkCompleted);
client.DoWorkAsync();
}
void client_DoWorkCompleted(object sender, DoWorkCompletedEventArgs e)
{
MessageBox.Show(e.Result);
}
{
InitializeComponent();
Service1Client client = new Service1Client();
client.DoWorkCompleted += new EventHandler<DoWorkCompletedEventArgs>
(client_DoWorkCompleted);
client.DoWorkAsync();
}
void client_DoWorkCompleted(object sender, DoWorkCompletedEventArgs e)
{
MessageBox.Show(e.Result);
}
5. 优先使用Silverlight模板和主题,微软默认为应用程序提供了4种主题供用户选择。在VS2010中还可以使用内置的导航应用程序模板,Blend4中还有一些关于MVVM的模板。一句话,除非有特别需要,否则不要开始从零开始你的应用程序。