0
votes

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?

2

2 Answers

1
votes

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

1
votes

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.

<i:Interaction.Triggers>
            <i:EventTrigger EventName="LoadingRow">
                <cmd:EventToCommand PassEventArgsToCommand="True"
                    Command="{Binding CheckForPrefetchCommand}" />
            </i:EventTrigger>
            <i:EventTrigger EventName="LoadingRow">
                <cmd:EventToCommand PassEventArgsToCommand="True"
                    Command="{Binding CheckForPrefetchCommand}" />
            </i:EventTrigger>
        </i:Interaction.Triggers>