如何更改RadListPicker中selectedIndex的值

本文关键字:selectedIndex 的值 RadListPicker 何更改 | 更新日期: 2023-09-27 18:00:16

在我的Windows Phone应用程序中,我正在重写OnNavigatedTo方法,以便用一些信息填充RadListPicker。我有两个数组:一个是大小为n的预填充DateTime数组,另一个是尺寸为n的预先填充字符串数组。我想将这两个数组分配给RadListPicker,这样字符串数组就是显示的内容,即用户所看到的选项,DateTimeArray就是RadListPicker.SelectedValue返回的内容。

当我尝试这种方式时,我得到了一个调试器中断

private void ShowResults(DateTime[] arrayDateTime, string[] arrayString, timeTypeEnum timeType)
        {
            radListPicker.ItemsSource = arrayString;
            radListPicker.SelectedValue = arrayDateTime;
            radListPicker.SelectedIndex = 4;
}

我该怎么解决这个问题?

如何更改RadListPicker中selectedIndex的值

奇怪的是,这个值arrayDateTimeDateTime[] Array,所以你需要选择ItemIndex或一些有序值,例如

radListPicker.SelectedValue = arrayDateTime[radListPicker.SelectedItemIndex];

您在这里混合类型。首先,您要将字符串类型的项目填充到列表选择器中。然后,稍后您告诉列表选择器选择DateTime类型的值。您需要确保两个数组都包含相同的类型(例如,两个带有字符串对象的数组或两个带有DateTime对象的数组)。

在谷歌上进行快速搜索时,我发现所选项目的设置也可以使用完成

radListPicker.SelectedItems.Add();

因此,在您的情况下,当两个数组都有相同类型的元素时,您可以使用:

private void ShowResults(DateTime[] selectedItems, DateTime[] allItems, timeTypeEnum timeType)
{
    radListPicker.ItemsSource = allItems;
    for (var item in selectedItems)
        radListPicker.SelectedItems.Add(item);
}