views:

88

answers:

1

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?

+1  A: 

Hey Ian,

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

LBugnion
Thanks Laurent. As you say I suspect it's the DataGrid event at the root of the problem, although the event fires fine and can be used with no problems in code behind.
irascian