2013-05-04 53 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> 

現在它可以訪問樣式中的列表框項目。