我正在使用新的 Windows Phone 8 LongListSelector
控制,它有它的 ItemsControl
分配给 List<Group<object>>
这样:
List<Group<PlacePoint>> searchResults;
async void doSearch()
{
this.searchResults = await SearchHelper.Instance.getSearchResults(txtSearchTerm.Text);
longList.ItemsSource = this.searchResults;
}
不幸的是,我第二次搜索时,重新设置 .ItemsSource 属性没有任何效果,控件只显示旧列表。
如何更改绑定(bind)?
最佳答案
似乎重新分配 longList.ItemsSource 没有任何效果,这是一个错误还是我不能说的设计。
但是,一个简单的解决方法是简单地使用 ObservableCollection>,然后使用这个集合而不是重新分配 ItemsSource。
示例代码:
ObservableCollection<Group<PlacePoint>> searchResults = new ObservableCollection<Group<PlacePoint>>();
public SearchPage()
{
InitializeComponent();
longList.ItemsSource = this.searchResults;
}
async void doSearch()
{
List<Group<PlacePoint>> tempResults = await SearchHelper.Instance.getSearchResults(txtSearchTerm.Text);
// Clear existing collection and re-add new results
this.searchResults.Clear();
foreach (Group<PlacePoint> grp in tempResults )
{
this.searchResults.Add(grp);
}
}
关于c# - WP8 LongListSelector - 重新分配 ItemsSource 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13650788/