【问题标题】:Issues removing a selected item from longlistmultiselector wp8从 longlistmultiselector wp8 中删除选定项目的问题
【发布时间】:2015-01-02 13:00:02
【问题描述】:

我有一个 longlistmultiselector,我需要在其中删除一个元素。 我可以从它的 itemsource 中删除该元素,但 UI 中没有反映出来。 UI界面没有变化。

以下是从 lonlistmultiselector(onboardList) 中删除项目的代码:

 var updatedReviewList = onboardList.ItemsSource;
            MessageBoxResult result = MessageBox.Show(Constants.DELETE_MSG, Constants.DELETE_MSG, MessageBoxButton.OKCancel);
            if (result == MessageBoxResult.OK)
            {
                if (reqDetails != null)
                {
                    for (var index = 0; index < onboardList.ItemsSource.Count; index++ )                    
                    // foreach (var item in onboardList.ItemsSource)
                    {
                        var item = onboardList.ItemsSource[index];

                        if (onboardList.SelectedItems.Contains(item))
                        {
                            //this.onboardList.ItemsSource.Remove(item);
                            updatedReviewList.Remove(item);

                        }
                    }

                    this.onboardList.ItemsSource = updatedReviewList;

                }

知道我可能缺少什么吗? 提前致谢

【问题讨论】:

    标签: windows-phone-8


    【解决方案1】:

    这样做..它应该工作。

    this.onboardList.ItemsSource = null;
    this.onboardList.ItemsSource = updatedReviewList;
    

    最好使用实现 INotifyPropertyChanged 的​​对象的 ObservableCollection。这将允许数据的两种方式绑定。如果从您的 itemsource 中删除了某些内容,它将反映在 UI 中,如果从 UI 中删除了某些内容,它将自动从您的 ObservableCollection 中删除该条目

    更多信息在这里:-

    http://msdn.microsoft.com/en-us/library/windows/apps/cc278072%28v=vs.105%29.aspx

    【讨论】:

    • 如果您希望的行为是以编程方式从列表中删除项目并让 UI 自动重新绑定集合,请务必考虑迁移您的数据源以使用此答案中提到的 ObservableCollection。
    猜你喜欢
    • 1970-01-01
    • 2013-08-18
    • 1970-01-01
    • 1970-01-01
    • 2014-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-14
    相关资源
    最近更新 更多