首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将多项设置为默认列表选择器-多项选择模式-windows电话

问将多项设置为默认列表选择器-多项选择模式-windows电话
EN

Stack Overflow用户
提问于 2013-12-18 13:29:38
回答 1查看 591关注 0票数 1

我需要在列表视图中设置默认选中的一些项,我正在做的是列表选择器加载的event.This工作正常。接下来,当用户更改这些选择时,我无法在列表选择器加载事件之前检索results.SelectionChanged事件,如果我在加载方法中添加事件处理程序,将它从XAML中删除,我将得到异常。

System.InvalidOperationException类型的未处理异常发生在System.Windows.ni.dll中

这是我的密码。

代码语言:javascript
复制
private void interestms_Loaded(object sender, RoutedEventArgs e)
        {
//selectedinterests is a string containing keys of selected interests seperated by commas.
            object[] split1 = selectedinterests.Split(',');
//interest is a dictionary with total list of interests
            var s = PhoneApplicationService.Current.State["interest"];

            List<object> finallist = new List<object>();
            var ss = (((System.Collections.Generic.Dictionary<string, string>)(s))).Keys;
            List<object> arr = new List<object>((((System.Collections.Generic.Dictionary<string, string>)(s))).Values);
            for (int k = 0; k < split1.Length; k++)
            {
                object getsel = arr[k];
                finallist.Add(getsel);
            }

         interestms.SelectedItems = hello;
        }

在selectionChange事件上,我将得到已单击的项,而不是已选中的项,因此,当取消选中项时,该项也将添加到selectedItems中。在本例中,我需要创建两个对象数组,一个包含值的总集合和其他选定的项,并删除both.In中的公共项,以便在加载事件之前调用selectionChanged方法。

请help.In案件任何其他细节是需要的,我很乐意提供..。

编辑:

代码语言:javascript
复制
private void interestms_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
//edited interst is an array object
               editedinterests.Add(e.AddedItems);
               var s = PhoneApplicationService.Current.State["interest"];

               List<object> arr = new List<object>((((System.Collections.Generic.Dictionary<string, string>)(s))).Values);

               var listcommon = arr.Intersect(editedinterests);
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-18 13:53:14

尝尝这个

代码语言:javascript
复制
private void interestms_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if(interestms.SelectedIndex==-1) return;

    //Here may be you get all selected items no need to maintain two array if you get all selected items.
    var listcommon = (cast as your type)interestms.SelectedItems;
    interestms.SelectedIndex=-1;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20659540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档