[英]MobileServiceCollection data binding to listbox
我正在开发连接到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;
}
将项目MobileServiceCollection绑定到列表框,就像绑定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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.