我正在使用 MVVM-Light EventToCommand 尝试从我的 ViewModel 实现预取机制,使用发布在 MVVM Light codeplex 站点上的 EventToCommand 示例代码。
不幸的是,即使我用作模型的 MouseMove 事件确实可以正常触发,该命令似乎也没有触发。
我是否错过了有关 DataGrid LoaddingRow 事件的一些时髦的东西,这意味着这将永远无法工作?
这是我的 XAML(将 MouseMove 事件人为地添加到混合中以证明基础知识):
<sdk:DataGrid x:Name="TaskDataGrid"
AutoGenerateColumns="True" CanUserReorderColumns="False"
CanUserResizeColumns="False" ItemsSource="{Binding UserTasks}">
<!-- LoadingRow="TaskDataGrid_LoadingRow"> -->
<i:Interaction.Triggers>
<i:EventTrigger EventName="LoadingRow">
<cmd:EventToCommand PassEventArgsToCommand="True"
Command="{Binding CheckForPrefetchCommand}" />
</i:EventTrigger>
<i:EventTrigger EventName="MouseMove">
<cmd:EventToCommand PassEventArgsToCommand="True"
Command="{Binding MoveMouseCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
等等
这是我的 ViewModel 中的代码:
public RelayCommand<MouseEventArgs> MoveMouseCommand
{
get;
private set;
}
public RelayCommand<DataGridRowEventArgs> CheckForPrefetchCommand
{
get;
private set;
}
并在 ViewModel 的构造函数中调用以下内容
CheckForPrefetchCommand = new RelayCommand<DataGridRowEventArgs>(e =>
{
// Do stuff here
int rowCount = e.Row.GetIndex();
});
MoveMouseCommand = new RelayCommand<MouseEventArgs>(e =>
{
var element = e.OriginalSource as UIElement;
var point = e.GetPosition(element);
string temp = string.Format("Position: {0}x{1}", point.X, point.Y);
});
MouseMove 的代码被命中,LoadingRow 的代码未被命中。我错过了什么?