【发布时间】:2013-12-18 13:29:38
【问题描述】:
我需要在列表视图中将某些项目设置为默认选中,我正在这样做是 listpicker 加载事件。这工作正常,接下来当用户更改这些选择时,我无法检索结果。SelectionChanged 事件之前被触发listpicker 加载事件,如果我在加载的方法中添加事件处理程序,从 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 中。在这种情况下,我需要创建两个对象数组,一个包含值的总集和其他选定的项目,并删除两者中的公共项目。这样做 selectionChanged 方法在加载事件之前被调用。
请帮忙。如果需要任何其他细节,我很乐意提供..
编辑:
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);
}
【问题讨论】:
-
能否提供选择更改事件的代码sn-ps
-
@Jaihind 是的,我已经添加了它..
标签: c# windows-phone-7 windows-phone-8 listpicker