WP8 LongListSelector - 重新分配 ItemsSource 无效 [英] WP8 LongListSelector - re-assigning ItemsSource has no effect

查看:20
本文介绍了WP8 LongListSelector - 重新分配 ItemsSource 无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用新的 Windows Phone 8 LongListSelector 控件,它的 ItemsControl 分配给了一个 List> 如此:

I'm using the new Windows Phone 8 LongListSelector control, which has its ItemsControl assigned to a List<Group<object>> as so:

    List<Group<PlacePoint>> searchResults; 

    async void doSearch()
    {
        this.searchResults = await SearchHelper.Instance.getSearchResults(txtSearchTerm.Text);
        longList.ItemsSource = this.searchResults;
    }

不幸的是,我第二次搜索时,重新设置 .ItemsSource 属性没有效果,控件只是显示旧列表.

Unfortunately, the second time that I search, re-setting the .ItemsSource property has no effect and the control simply displays the old List.

如何更改绑定?

推荐答案

重新分配 longList.ItemsSource 似乎没有任何效果,这是一个错误还是设计使我无法说.

It would seem that re-assigning longList.ItemsSource does not have any effect, whether this is a bug or by design I can't say.

但是,一个简单的解决方法是使用 ObservableCollection> 代替,然后使用此集合而不是重新分配 ItemsSource.

However, an easy workaround is simply to use an ObservableCollection> instead and then work with this collection rather than re-assigning the 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);
        }
    }

这篇关于WP8 LongListSelector - 重新分配 ItemsSource 无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆