2014-12-07 68 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