多个silverlight异步调用和组合框源
本文关键字:组合 调用 silverlight 异步 多个 | 更新日期: 2023-09-27 18:16:30
我有3个组合框和每个组合框需要不同的来源。对于每个源,我都有WCF服务,并且每个服务都在同一时间异步调用。我的问题是,当最后一个服务完成时,每个组合框都是填充的,它们都在等待最长的服务。当他的服务完成时,我需要填充combobox。
我代码:public ArtiklViewModel Artikl;
public ItemNewEdit(ArtiklViewModel _artikl, bool _edit)
{
InitializeComponent();
Artikl = _artikl;
SifarnikServiceClient service1 = new SifarnikServiceClient();
service1.GetSifarniksByVrstaAsync(1);
service1.GetSifarniksByVrstaCompleted += new EventHandler<GetSifarniksByVrstaCompletedEventArgs>(service_GetSifarniks1Completed);
SifarnikServiceClient service2 = new SifarnikServiceClient();
service2.GetSifarniksByVrstaAsync(2);
service2.GetSifarniksByVrstaCompleted += new EventHandler<GetSifarniksByVrstaCompletedEventArgs>(service_GetSifarniks2Completed);
SifarnikServiceClient service3 = new SifarnikServiceClient();
service3.GetSifarniksByVrstaAsync(3);
service3.GetSifarniksByVrstaCompleted += new EventHandler<GetSifarniksByVrstaCompletedEventArgs>(service_GetSifarniks3Completed);
}
void service_GetSifarniks1Completed(object sender, GetSifarniksByVrstaCompletedEventArgs e)
{
combo1.ItemsSource = e.Result.ToList();
if (Artikl != null)
combo1.SelectedValue = Artikl.JmjID;
}
void service_GetSifarniks2Completed(object sender, GetSifarniksByVrstaCompletedEventArgs e)
{
combo2.ItemsSource = e.Result.ToList();
if (Artikl != null)
combo2.SelectedValue = Artikl.GrupaID;
}
void service_GetSifarniks3Completed(object sender, GetSifarniksByVrstaCompletedEventArgs e)
{
combo3.ItemsSource = e.Result.ToList();
if (Artikl != null)
combo3.SelectedValue = Artikl.TarifaID;
}
这是基于Xaml的ui(如Silverlight和UWP)的常见问题。问题是标准的Microsoft Selector控件不支持异步。它们关心ItemsSource和SelectedItem的设置顺序。我昨天提出了一个解决方案。它很复杂,但很全面。你也许想看一看。
https://stackoverflow.com/questions/36003805/uwp-silverlight-combobox-selector-itemssource-selecteditem-race-condition-solu