我有一个风格的LongListBoxItem,每一个项目有一个图片和描述。因此,应该调用不同的事件,取决于所接触的对象(图片或desc)。我用的是Mvvmlight。
问题是我完全迷失在事件案例和事件参数中。我在尝试不同的事件:
Tap事件+ PassEventArgsToCommand =返回GestureEventArgs,不确定是否能够从其中提取项id
SelectedItem事件+ PassEventArgsToCommand =返回SelectionChangedEventArgs,但从不触发(可能是因为事件不是从listbox项中上升的,而是从其子节点开始的)
点击事件+ CommandParameter="{Binding SelectedItem,ElementName=ProductCategoriesListBox}“=无法从样式中找到元素名,因为我将多次使用它
SelectedItem事件+ CommandParameter="{Binding SelectedItem,ElementName=ProductCategoriesListBox}“=好,同样的事情
也许有更好的方法来完成我的任务?
发布于 2013-05-05 09:14:28
好的,所以TemplatedParent就是这个例子中的resque (第5行)。
<interactivity:Interaction.Triggers>
<interactivity:EventTrigger EventName="Tap">
<command:EventToCommand
Command="{Binding Source={StaticResource ViewModelLocator}, Path=NavigationViewModel.OnTapItemCommand, Mode=OneWay}"
CommandParameter="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DataContext}"/>
</interactivity:EventTrigger>
</interactivity:Interaction.Triggers>现在可以从样式访问列表框项了。
https://stackoverflow.com/questions/16379444
复制相似问题