[英]How to handle a selected item of LongListMultiSelector?
I want to be able: 我希望能够:
So I choosed LongListMultiSelector
. 所以我选择了
LongListMultiSelector
。
In built in LongListSelector
, I handle the SelectionChanged
event like this: 在内置的
LongListSelector
,我这样处理SelectionChanged
事件:
private void mails_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selectedItem = mailsLongListSelector.SelectedItem as Mail;
if (selectedItem == null)
return;
...
mailsLongListSelector.SelectedItem = null;
}
I want exactly like that functionality in wptoolkit's LongListMultiSelector
. 我想要与wptoolkit的
LongListMultiSelector
中的功能完全一样。 like when you select an email to open and read it. 例如当您选择要打开并阅读的电子邮件时。
LongListMultiSelector 's SelectionChanged
occurs when you tap left side of an item and checkboxes appear. 当您点击项目左侧时,就会出现LongListMultiSelector的
SelectionChanged
,并出现复选框。 this is not what I want. 这不是我想要的。
The Question is: How can I perform something when the user taps on one item of LongListMultiSelector ? 问题是:当用户点击LongListMultiSelector的一项时,如何执行某些操作 ? thanks.
谢谢。
You could try this. 你可以试试看。 If this is your LongListSelector
如果这是您的LongListSelector
<tkit:LongListMultiSelector Name="longlist" SelectionChanged="longlist_SelectionChanged">
<tkit:LongListMultiSelector.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}" FontSize="32" Tap="TextBlock_Tap"/>
</DataTemplate>
</tkit:LongListMultiSelector.ItemTemplate>
</tkit:LongListMultiSelector>
and it has an itemtemplate, you can detect a tap on item. 它具有一个itemtemplate,您可以检测到对项目的点击。
private void TextBlock_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
var itemTapped = (sender as FrameworkElement).DataContext as Book;
}
and still have a selection changed 仍然有选择更改
private void longlist_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
Once you are using LongListMultiSelector, the SelectionChanged event is fired when item is added or removed. 一旦使用LongListMultiSelector,添加或删除项目时就会触发SelectionChanged事件。 If you want to perform the action regardless item is added/removed, I've managed to do it like this (for a simple string):
如果您想执行操作而不管添加/删除了项目,我已经设法做到这一点(对于一个简单的字符串):
private void longlist_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string selectedItem = String.Empty;
if (e.AddedItems.Count > 0) selectedItem = e.AddedItems[0] as string;
else selectedItem = e.RemovedItems[0] as string;
MessageBox.Show(selectedItem); // do your work
}
It should run while items are selected separately by tapping, but this method will have problems when more items are added/removed at the same time - if you need it, then you should handle this also. 它可以在通过单击分别选择项目时运行,但是当同时添加/删除更多项目时,此方法会出现问题-如果需要,则也应进行处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.