2014-12-07 70 views
0

你知道是否有可能使用XAML從WPF中的ListView中獲取MouseOver上的元素? 我想將鼠標移到元素上來綁定命令參數。WPF XAML ListView MouseOverItem

我應該在路徑中輸入什麼?

<i:Interaction.Triggers> 
    <i:EventTrigger EventName="MouseEnter"> 
     <i:InvokeCommandAction Command="{Binding SetOnMousePlayerCommand}" 
     CommandParameter="{Binding ElementName=leftPlayersListViewGame, Path=XXX}"/> 
    </i:EventTrigger> 
</i:Interaction.Triggers> 

也許我必須以另一種方式做到這一點?你能告訴我如何?

+0

當鼠標懸停在它上面時,您是否想知道ListView中存在什麼樣的UI元素? – 2014-12-07 12:33:17

+0

這個問題的答案應該有所幫助:http://stackoverflow.com/questions/4294945/wpf-listview-mouseover-item – Gus 2014-12-07 12:34:13

+0

ListView關聯我的自定義控件; Gus,謝謝你,但它可能做到沒有代碼後面嗎? – user2811005 2014-12-07 13:31:49

回答

0

如果你正在尋找在這裏訪問事件參數應該如何進行:

<i:Interaction.Triggers> 
<i:EventTrigger EventName="MouseEnter"> 
    <command:EventToCommand Command="{Binding Mode=OneWay,Path=MouseEnterCommand}" PassEventArgsToCommand="True"/> 
</i:EventTrigger> 
</i:Interaction.Triggers> 

private RelayCommand<MouseEventArgs> _mouseEnterCommand; 
public RelayCommand<MouseEventArgs> MouseEnterCommand 
{ 
    get 
    { 
     return _mouseEnterCommand 
      ?? (_mouseEnterCommand= new RelayCommand<MouseEventArgs>(
      (s) => 
      { 
       //your logic 
      })); 
    } 
} 

,但如果你正在尋找的事件的發送者,所以這裏是你的答案Pal: Passing event args and sender to the RelayCommand