如何清除LongListSelector选择 [英] How to clear LongListSelector selection

查看:58
本文介绍了如何清除LongListSelector选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用LongListSelector控制导航。   LongListSelector有许多项目。点击一个项目,弹出一个详细的用户控件。  点击后退箭头,您将返回选择全景图。  确定正常工作,直到您单击LongListSelector中的确切
相同项目。  由于已经选择了SelectedItemChanged事件,因此未触发详细用户控件。


在导航到用户控件后,我们需要清除LongListSelector选择。  似乎无法了解如何做到这一点。


谢谢

解决方案

重置通过将SelectedItem设置为null来进行选择。请注意,这将触发SelectionChanged事件,因此您必须检查它。典型的处理程序如下所示:


 //在LongListSelector上更改句柄选择
private void MyLongListSelector_SelectionChanged(object sender,SelectionChangedEventArgs e)
{
//如果所选项目为空(无选择)则不执行任何操作
if(MyLongListSelector.SelectedItem == null)
return;

//执行处理...

//将所选项重置为空(无选择)
MyLongListSelector.SelectedItem = null;
}


要查看工作示例,请打开一个新的WP8项目并选择Windows Phone Databound App模板。


Using a LongListSelector to control navigation.  LongListSelector has a number of items. Tap on an item and a detail user control pops up.  Hit the back arrow and you are back at the selection panorama.  OK works fine until you click the exact same item in the LongListSelector.  Since it is already selected the SelectedItemChanged event doesnt fire so the detail user control isnt navigated to.

Figure after we navigate to the user control we need to clear the LongListSelector selection.  Cant seem to find out how to do that.

Thanks

解决方案

Reset the selection by setting SelectedItem to null. Note that this will trigger SelectionChanged event, so you have to check for it. A typical handler looks like this:

    // Handle selection changed on LongListSelector
    private void MyLongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        // If selected item is null (no selection) do nothing
        if (MyLongListSelector.SelectedItem == null)
            return;

        // perform your processing...

        // Reset selected item to null (no selection)
        MyLongListSelector.SelectedItem = null;
    }

To see a working example, open a new WP8 project and select the Windows Phone Databound App template.


这篇关于如何清除LongListSelector选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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