简体   繁体   English

如何处理LongListMultiSelector的选定项目?

[英]How to handle a selected item of LongListMultiSelector?

I want to be able: 我希望能够:

  • to open a mail when the user taps on one item. 当用户点击一项时打开邮件。
  • and delete multiple emails when the user selects multiple emails 并在用户选择多个电子邮件时删除多个电子邮件

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. 当您点击项目左侧时,就会出现LongListMultiSelectorSelectionChanged ,并出现复选框。 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.

相关问题 如何处理LongListMultiSelector的选定项目? - How do I handle a selected item of LongListMultiSelector? 如何将某些项设置为LongListMultiSelector之前选择的某些项 - How to set item some as selected, that was selected before of LongListMultiSelector LongListMultiSelector阻止所选项目的手势事件 - LongListMultiSelector blocks gesture events for selected items 如何在LongListMultiSelector中插入ToggleSwitch控件 - How to insert ToggleSwitch Control in LongListMultiSelector WP8:LongListMultiSelector点击项目触发MVVM - WP8: LongListMultiSelector Tap Item Trigger MVVM 如何处理Windows Phone中所选枢轴项的事件 - How do i handle the event of a selected pivot item in Windows Phone WP8 LongListMultiSelector无法删除所选项目 - WP8 LongListMultiSelector Can't Remove Selected Items LongListMultiSelector在WP8上未获取父项的宽度 - LongListMultiSelector doesn't get width of parent item on WP8 如何在选择模式下锁定工具箱:LongListMultiSelector? - How can i lock toolkit:LongListMultiSelector in selection mode? 如何在LongListMultiSelector中更改CheckBox和CheckBox刻度的颜色? WP8 - How to change the CheckBox and CheckBox tick's color in LongListMultiSelector? WP8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM