我正在使用WCF服务
我有这个问题:
当我在异步函数调用开始时从服务器为我的GridView检索数据时,我设置了IsBusy = "True"。在调用该方法之后,我设置了IsBusy = "False"。在方法调用期间,不显示RadBusyIndicator。我不明白问题出在哪里。
我已经上传了一个简单的项目与这个问题。你能检查一下吗?Download
发布于 2013-03-19 19:28:46
我在BackgroundWorker中移动了加载,你能试试这个吗:
private void LoadData()
{
//Activate BudyIndicator
App.Instance.SetBusy();
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += (o, ea) =>
{
ObservableCollection<CustomerModel> LoadedCustomers = null;
//Create Client
proxy.ServicesClient client = new proxy.ServicesClient();
ObservableCollection<Customer> customers = client.GetCustomers();
LoadedCustomers = new ObservableCollection<CustomerModel>();
foreach (var item in customers)
{
LoadedCustomers.Add(new CustomerModel()
{
CustomerId = item.CustomerId,
Title = item.Title,
FirstName = item.FirstName,
MiddleName = item.MiddleName,
LastName = item.LastName,
CompanyName = item.CompanyName,
SalesPerson = item.SalesPerson,
EmailAddress = item.EmailAddress,
Phone = item.Phone
});
}
client.Close();
//Define return value
ea.Result = LoadedCustomers;
};
worker.RunWorkerCompleted += (o, ea) =>
{
//Get returned value
ObservableCollection<CustomerModel> model = ea.Result as ObservableCollection<CustomerModel>;
if (model != null)
{
Customers = model;
}
//Desactivate BusyIndicator
App.Instance.UnSetBusy();
};
worker.RunWorkerAsync();
}发布于 2013-03-20 00:32:50
好的,我明白你的问题了。代理上的Close方法等待异步调用的结果。只需在GetCustomersCompleted方法中移动您的client.Close();,这将会起作用。(使用您的样本进行测试)
private proxy.ServicesClient client = null;
private void LoadData()
{
App.Instance.SetBusy();
client = new proxy.ServicesClient();
client.GetCustomersCompleted += (s, e) =>
{
if (e.Error != null)
{
throw new Exception();
}
else
{
Customers = new ObservableCollection<CustomerModel>();
foreach (var item in e.Result)
{
Customers.Add(new CustomerModel()
{
CustomerId = item.CustomerId,
Title = item.Title,
FirstName = item.FirstName,
MiddleName = item.MiddleName,
LastName = item.LastName,
CompanyName = item.CompanyName,
SalesPerson = item.SalesPerson,
EmailAddress = item.EmailAddress,
Phone = item.Phone
});
}
OnPropertyChanged("Customers");
}
client.Close();//Close after the return
App.Instance.UnSetBusy();
};
client.GetCustomersAsync();
//client.Close();
}
}发布于 2013-03-21 11:19:55
如果您的窗口xaml不在忙指示器内,它可能不会显示。使用该控件,当繁忙指示器设置为true时,您需要将希望屏蔽的内容放在指示器标记内。如果您的UserControl的主要显示项是一个网格,则将该网格包含在繁忙指示器标记中。
<UserControl>
<telerik:RadBusyIndicator IsBusy={Binding Busy}>
<Grid>
content...
</Grid>
</telerik:RadBusyIndicator>
</UserControl>这应该会给你想要的结果。
https://stackoverflow.com/questions/15497169
复制相似问题