【发布时间】:2016-12-22 22:51:02
【问题描述】:
我有一个绑定到 ViewModel 的 ListView。 我想选择右键单击的 ListViewItem 以及触发更改 ViewModel 属性的触发器。(选择模式为单一)。
<ListView MinHeight="50" MaxHeight="120"
ItemsSource="{Binding Path=DisplayItems}" SelectedItem="{Binding Path=SelectedDisplayItem, Mode=TwoWay}"
ItemTemplate="{StaticResource SelectedDisplayItemTemplate}"
IsItemClickEnabled="False"
helpers:AttachedCommand.Command="{Binding Path=Commands[NavigateToDisplayItem]}"
helpers:AttachedCommand.Event="Tapped" />
我已尝试处理 ListView 中的 Right Tapped 事件,但无法获取被点击的项目。如何在右键单击时更改所选项目,并在选中时将 SelectedDisplayItem 设置为右键单击项目?
【问题讨论】:
-
既然您将
ItemTemplate设置为SelectedDisplayItemTemplate,当您在那里设置RightTapped事件时会发生什么? -
好吧,因为它是一个模板并从样式文件中获取其内容,所以我不想在那里放置 RightTapped。
-
也许您可以将您的 itemtemplate 设为用户控件并在其中处理 RightTapped。
标签: c# xaml windows-runtime uwp