数据绑定全解析:从基础到高级应用
1. 数据服务调用
在使用数据服务时,首先要在项目里添加一个Web引用。完成此步骤后,就可以在应用程序中使用自动生成的Web服务代码。以 StoreDbClient 类为例,当用户点击“Get Product”按钮时,会执行以下代码:
private void cmdGetProduct_Click(object sender, RoutedEventArgs e)
{
// Set the URL, taking the port of the test web server into account.
StoreDbClient client = new StoreDbClient();
// Call the service to get the Product object.
client.GetProductCompleted += client_GetProductCompleted;
client.GetProductAsync(356);
}
当Web服务返回数据时,需要设置容器的 DataContext 属性,代码如下:
private void client_GetProductCompleted(object sender,
GetProductCompletedEventArgs e)
{
try
{
超级会员免费看
订阅专栏 解锁全文
1168

被折叠的 条评论
为什么被折叠?



