我需要在列表视图中设置默认选中的一些项,我正在做的是列表选择器加载的event.This工作正常。接下来,当用户更改这些选择时,我无法在列表选择器加载事件之前检索results.SelectionChanged事件,如果我在加载方法中添加事件处理程序,将它从XAML中删除,我将得到异常。
System.InvalidOperationException类型的未处理异常发生在System.Windows.ni.dll中
这是我的密码。
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案件任何其他细节是需要的,我很乐意提供..。
编辑:
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);
}发布于 2013-12-18 13:53:14
尝尝这个
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;
}https://stackoverflow.com/questions/20659540
复制相似问题