我正在开发一款连接到windows azure的应用。我有一个列表框,将显示项目名称。与azure的连接工作,我得到有效的结果,但列表框似乎没有得到更新(视觉上)。如果我添加一个可观察的集合并将项目添加到此集合中并且列表框已正确连接,则它可以正常工作。
知道为什么这不起作用吗?
这是我的代码:
public MobileServiceCollection<Project, Project> Projects { get; private set; }
private IMobileServiceTable<Project> projectTable = App.MobileService.GetTable<Project>();
public async void LoadData()
{
try
{
Projects = await projectTable
.Where(Project => Project.ID != 0)
.ToCollectionAsync();
}
catch (MobileServiceInvalidOperationException e)
{
MessageBox.Show(e.Message, "Error loading projects", MessageBoxButton.OK);
}
this.IsDataLoaded = true;
}
答案 0 :(得分:0)
将您的Projects MobileServiceCollection绑定到Listbox,就像绑定ObservableColleciton一样
try
{
Projects = await projectTable
.Where(Project => Project.ID != 0)
.ToCollectionAsync();
//Bind Projects to ListBox
ListBox.ItemsSource = Projects;
}
此外,当您使用IMobileServiceTable插入/更新/删除项目时,您必须通过更新集合来保持MobileServiceCollection的同步
//Add a new project to the database
await projectTable.InsertAsync(project);
//Update the collection to match the database
Projects.Add(project);