我需要在Silverlight列表框中顯示WCF服務返回值(LIST)。ObservableCollection沒有綁定列表框中的數據
創建GetAllAgents類一樣,
public class GetAllAgents
{
public List<string> FirstName { get; set; }
public GetAllAgents(List<string> firstName)
{
FirstName = firstName;
}
}
用於消費WCF服務
public partial class AgentQueue : UserControl
{
ChatACDService.ChatACDServiceClient ChatAcdClient = new ChatACDService.ChatACDServiceClient();
public ObservableCollection<GetAllAgents> _GetAllAgents = new ObservableCollection<GetAllAgents>();
public AgentQueue()
{
InitializeComponent();
LoadAgentList();
this.AllList.DataContext = _GetAllAgents;
}
private void LoadAgentList()
{
ChatAcdClient.GetAllAgentListCompleted += new EventHandler<GetAllAgentListCompletedEventArgs>(ChatAcdClient_GetAllAgentListCompleted);
ChatAcdClient.GetAllAgentListAsync();
}
void ChatAcdClient_GetAllAgentListCompleted(object sender, GetAllAgentListCompletedEventArgs e)
{
if (e.Error != null)
{
}
else
{
// AllAgents.ItemsSource = e.Result;
_GetAllAgents.Add(new GetAllAgents(e.Result.ToList()));
}
}
我用下面的代碼創建列表框XAML頁面下面的方法
<ListBox x:Name="AllList" ItemsSource="{Binding}"
DisplayMemberPath="FirstName"
Margin="403,54,0,35" HorizontalAlignment="Left" Width="101" />
但是輸出像,
我需要顯示WCF方法的結果(返回類型列表)在列表框中使用ObservableCollection.What是變化需要在上面的程序?
顯示如何設置DataContext。 – Maximus
@Maximus this.AllList.DataContext = _GetAllAgents; AllList是Listbox的名稱 –
你期望什麼? FirstName返回的對象就是您在輸出中看到的列表。你期望得到什麼結果? – Nitram