使用 MVVM-Light EventToCommand 的 Silverlight 4 DataGrid LoadingRow 事件未触发?
我正在使用 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 不是。我缺少什么?
I'm using the MVVM-Light EventToCommand to try and implement a pre-fetching mechanism from my ViewModel, using the sample code for EventToCommand that's posted on the MVVM Light codeplex site.
Unfortunately the command doesn't seem to fire, even though the MouseMove event which I used as my model does fire fine.
Am I missing something funky about the DataGrid LoaddingRow event that means this will never work?
Here's my XAML (with MouseMove event artificially added to the mix to prove out the basics):
<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>
etc.
Here's the code in my ViewModel:
public RelayCommand<MouseEventArgs> MoveMouseCommand
{
get;
private set;
}
public RelayCommand<DataGridRowEventArgs> CheckForPrefetchCommand
{
get;
private set;
}
and in the constructor for the ViewModel the following gets called
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);
});
The code for the MouseMove is hit, the code for the LoadingRow isn't. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是我第一次听到有关某些 DataGrid 事件的抱怨。我没有时间去研究它,但我认为这个控制有问题。我将与 MSFT 核实并回复您。
干杯,
洛朗
It's not the first time I hear this complaint about some DataGrid events. I didn't have time to look into it, but I think there is something wrong with that control. I will check with MSFT and get back to you.
Cheers,
Laurent
我在 WPF 中遇到这个问题。
经过多次尝试,我找到了解决方案,但对我来说仍然不合逻辑。
解决方案是为同一事件 LoadingRow 调用事件触发器两次。
它对我有用,需要调整一些东西。
不知道我的提议能否帮助LBugnion先生解决问题,无论如何我分享给你。
I have this problem with WPF.
After many attempts, i found a solution but it's still not logical for me.
the solution is to call the Event trigger two time for the same event LoadingRow.
it works for me with some things to adjust.
I don't know if my proposition can help Mr LBugnion to solve the problem, Any way i share it with you.