LongListSelector:项目挖掘? [英] LongListSelector: Item tap?

查看:110
本文介绍了LongListSelector:项目挖掘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Windows Phone 8 LongListSelector控制和想不出来处理一个项目一个水龙头的最佳途径。
我已经找到了几个例子依靠SelectionChanged事件。但是,这个方案是越野车,因为如果我点击打开一个新页面中的项目,打回来,然后再次点击相同的项目,因为这个项目已经被选中它不会工作,那么的SelectionChanged不会被触发。

I am using LongListSelector control on Windows Phone 8 and can't figure out the best way to handle a tap on an item. The few examples I've found rely on the SelectionChanged event. However, this solution is buggy because if I tap an item that opens a new page, hit back, and then tap the same item again, it won't work because this item is already selected, so SelectionChanged is not triggered.

我试着注册到自来水事件,并使用当前所选项目作为抽头之​​一,但有时当前选择的项目是不是我期望的。

I tried to register to the tap event and use the current selected item as the tapped one, but some times the current selected item is not the one I expect.

我可以总结我的ItemTemplate在按钮和处理每个项目的水龙头,但我需要reskin按钮,使它看起来像一个简单的列表项。

I could wrap my ItemTemplate in a button and handle the tap for each item but I need to reskin the button to make it look like a simple list item.

最后,我不明白为什么它是如此复杂,要达到这样一个基本的东西。有一个简单的和标准的方式,我错过了吗?

Finally, I don't understand why it is so complicated to achieve such a basic thing. Is there a simple and standard way I missed?

我的第二个愿望是当它被窃听得到关于该项目的效果。有没有做任何标准的方式?

My second wish is to get an effect on the item when it is tapped. Is there any standard way to do it?

推荐答案

您可以您LongListSelector的的SelectedItem 在每个的SelectionChanged 事件的结束。即。

You could null your LongListSelector's SelectedItem at the end of each SelectionChanged event. I.e.

<phone:LongListSelector x:Name="LLS" SelectionChanged="LLS_SelectionChanged">

和事件处理程序:

private void LLS_SelectionChanged(object sender, SelectionChangedEventArgs e) {

  // If selected item is null, do nothing
  if (LLS.SelectedItem == null)
    return;

  // Navigate to the next page
  NavigationService.Navigate(new Uri("/nextpage.xaml", UriKind.Relative));

  // Reset selected item to null
  LLS.SelectedItem = null;
}

您会触发SelectionChanged事件两次,但没有什么事情发生绕第二圈时,你应该得到你要找的行为 - (即设置的SelectedItem 将引发新的SelectionChanged 事件,但本次事件被逮住的if语句)

You'll fire the SelectionChanged event twice, but nothing's going to happen the second time round and you should get the behaviour that you're looking for - (i.e Setting SelectedItem to null will trigger a new SelectionChanged event, but this second event gets caught in the if-statement)

至于你的问题的第二部分,你可能会更好张贴的新问题。

As for the second part of your question, you might be better posting a new question.

这篇关于LongListSelector:项目挖掘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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