如何实现“全选”使用longlistmultiselector?问题。 [英] How to implement a "Select All" with the longlistmultiselector? Issues.

查看:41
本文介绍了如何实现“全选”使用longlistmultiselector?问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试做一些会执行"select-all"的代码功能。为了实现这一点,在Code Behind中我试图手动将所有列表对象添加到LongListMultiSelector的SelectedItems。

I'm trying to do some code that will do a "select-all" function. To achieve this, in the Code Behind I am trying to manually add all the list objects to the SelectedItems of the LongListMultiSelector.


然而问题是,当我这样做时,列表会被两个项目增加,信息相同。我尝试过使用SelectedItems.Add(...),SelectedItems.Insert(...)无济于事。

The issue however is that when I do this, the list is augmented by two of the items, identical in their information. I have tried using SelectedItems.Add(...), SelectedItems.Insert(...) to no avail.


I还尝试使用SelectedItems.Remove(...),SelectedItems.RemoveAt(...)立即从列表中删除其中一个项目,这将实际删除这两个条目,无论我实际删除哪个条目。

I have also tried to immediately remove one of the items from the list using SelectedItems.Remove(...), SelectedItems.RemoveAt(...) which will actually remove both entries, regardless of which I actually remove.


最后,我尝试将其中一个条目更改为NULL。这实际上删除了列表中的一个条目,但随后将剩余的条目更改为空对象本身。我是否以正确的方式执行此SelectAll功能?对于我想要实现的目标,是否有更好的替代品
?是否有可能继续我正在做的事情并解决这个重复问题?

Lastly, I've tried changing one of the entries to NULL. This actually removes one of the entries in the list, but subsequently changes the remaining one to a null object itself. Am I doing this SelectAll feature in the right way? Is there a better alternative for what I want to achieve? Is it possible to continue with what I am doing and fix this duplication issue?


另外,我发现在早期的一个非常类似的帖子,但没有解决方案是  找到 ,建议不适用于
me。 

Also, I realize a very similar post was made in early feb, but no solution was found, and the suggestions work not for me. 

我查看了你的建议,因为我遇到了同样的问题,这对我来说很有意义。但是,当我实现它时它仍然不起作用。我有一个字符串的LongListMultiSelector,只是字符串。但是当我尝试
代码时,我得到一个NullPointException。下面是我的具体实现:

I looked over your suggestion as I am having the same issue and it makes a heckuva lot of sense to me. However it still doesn't work when I implement it. I have a LongListMultiSelector of strings, just strings. However I get a NullPointException when I try the code. Below is my specific implementation:

this.List_Saves.SelectedItems.Clear();
List<string> allData = this.List_Saves.ItemsSource as List<string>;
allData.ForEach(item => (List_Saves.ContainerFromItem(item) as LongListMultiSelectorItem).IsSelected = true);

首先,这个中断发生在这里:

At first this break happens here:

List<string> allData = this.List_Saves.ItemsSource as List<string>;

并且无论allData从未被任何东西填充。我把它归结为我的ItemSource是一个ObservablCollection,而不是一个List,但我不确定。所以我重写它希望它能如下工作:

And no matter what allData never gets populated with anything. I chalk this up to my ItemSource being an ObservablCollection and not exactly a List, but I'm unsure. So I re-wrote it in hopes it would work as below:

foreach (string tim in allLists)
{
    (List_Saves.ContainerFromItem(tim) as LongListMultiSelectorItem).IsSelected = true;
}




其中allLists是我的ObservableCollection,List_Saves是我的LongLisMultiselector。此时我仍然得到一个NullPointException。

我查找了API def为"ContainerFromItem"它表示如果项目不在列表中,则返回Null。但显然字符串在Itemsource中,所以我不确定该从这里查看什么。


Where allLists is my ObservableCollection and List_Saves is my LongLisMultiselector. At this point I still get a NullPointException.
I looked up the API def for "ContainerFromItem" and it says it returns Null if the item isn't in the list. But clearly the string is in the Itemsource, so I'm not sure what to check from here.


推荐答案

您好,

您是否考虑过下载
LongListMultiSelector的源代码?
然后调试并分析代码本身?

Have you considered downloading the source code for the LongListMultiSelector and then debugging and analyzing the code itself?

希望这会有所帮助,

Mark

Hope this helps,
Mark


这篇关于如何实现“全选”使用longlistmultiselector?问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆