2013-05-04 69 views
0

我有一个LongListBoxItem风格,每个项目都有一个图片和说明。所以,应该调用不同的事件,取决于被触摸的对象(pic或desc)。我正在使用Mvvmlight。绑定EventToCommand风格

问题是我完全失去了事件情况和事件参数。我想不同的事件:


点击事件+ PassEventArgsToCommand =回报GestureEventArgs,不知道如果我能够从那里提取商品ID

的SelectedItem事件+ PassEventArgsToCommand =回报SelectionChangedEventArgs,但从来没有火灾(可能是因为事件不是从列表框项目上升,而是从其列表框项目上升,但从其childern,边框)

Tap event + CommandParameter =“{Binding SelectedItem,ElementName = ProductCategoriesListBox}”=无法找到元素名称,多次使用它

的SelectedItem事件+ CommandParameter = “{结合的SelectedItem,的ElementName = ProductCategoriesListBox}”=好,同样的事情


也许有我的任务更好的方法?

回答

0

好的,所以TemplatedParent是在这种情况下(第5行)的resque。

<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> 

现在它可以访问样式中的列表框项目。