-->

LongListSelector:项目挖掘?(LongListSelector: Item tap?

2019-07-18 00:08发布

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

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

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

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

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

Answer 1:

你可以null你LongListSelector的SelectedItem在每年年底SelectionChanged事件。 即

<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事件的两倍,但什么也没有要轮发生第二次,你应该得到你要寻找的行为- (即设置SelectedItemnull将掀起新SelectionChanged事件,但是这第二个事件被抓住在if语句)

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



Answer 2:

我与点击事件处理做了。

我不喜欢使用选定的属性,但得到挖掘项目这种方式(我还没有发现任何错误):

MyListItemClass item = ((FrameworkElement)e.OriginalSource).DataContext 
                                                             as MyListItemClass;

此外,您可以通过从的VisualTree导航e.OriginalSource得到了简单的ContentPresenter原始项目。 那样:

ContentPresenter itemPresenter = SomeHelperClass
                              .FindParent<ContentPresenter>(e.OriginalSource,"");

其中FindParent类似于找到孩子这样一个问题: 我如何才能找到WPF控件按名称或类型?

ContentPresenter是对象,你需要手动更改的项目模板,如果你想(设置如“选择”的状态)。



Answer 3:

 private void Item_tap(object sender, RoutedEventArgs e)
        {
            var element = (FrameworkElement)sender;
            DataSource data = (DataSource)element.DataContext;


        }


Answer 4:

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

为此,您需要做的添加到您的控制(或StackPanel中要产生这样的效果)的唯一的事情:

<StackPanel toolkit:TiltEffect.IsTiltEnabled="True">


Answer 5:

首先添加这里面的*的.xaml页

LongListSelectorSelectionChanged="listBox_SelectionChanged"

这样它看起来像这样:

<toolkit:LongListSelector x:Name="listBox" SelectionChanged="listBox_SelectionChanged">

然后在* .xaml.cs文件在事件处理程序

private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    // Write your logic on what you want to do with the selected item
}


Answer 6:

除了halil's回答:

首先,你需要的NuGet安装了Windows Phone工具包(WPtoolkit)。 不是添加上的PhoneApplicationPage的命名空间声明。

xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"

在此之后,你可以添加toolkit:TiltEffect.IsTiltEnabled="True"的控制定义。

它是由NOKIA不错documneted: http://developer.nokia.com/community/wiki/Tilt_Effect_for_Windows_Phone

奥利弗



文章来源: LongListSelector: Item tap?