Search code examples
xamluwpmvvm-lighttemplate10

uwp GridView Drop EventTriggerBehavior signature


I'm working on a Drag and Drop Xaml Uwp application with multiple ComboBox and GridView. I experimented with it a bit in xaml code behind until I thought I knew where I was heading with the app. I then began moving my logic into a ViewModel, PlayPageViewModel, I'm using MvvM Light and Template 10. I have many events working using interactions. I've had the Drop working in codeBehind when I move it over to the view model I get Cannot find method named GvNewPlayList_OnDrop on object of type TheLolFx.UWP.T10.ViewModels.PlayPageViewModel that matches the expected signature.

Exception

        Exception   {System.ArgumentException: Cannot find method named    GvNewPlayList_OnDrop on object of type TheLolFx.UWP.T10.ViewModels.PlayPageViewModel that matches the expected signature.
       at Microsoft.Xaml.Interactions.Core.CallMethodAction.Execute(Object sender, Object parameter)
       at Microsoft.Xaml.Interactivity.Interaction.ExecuteActions(Object sender, ActionCollection actions, Object parameter)
       at Microsoft.Xaml.Interactions.Core.EventTriggerBehavior.OnEvent(Object sender, Object eventArgs)}   System.Exception {System.ArgumentException}

Message

Message "System.ArgumentException: Cannot find method named GvNewPlayList_OnDrop on object of type TheLolFx.UWP.T10.ViewModels.PlayPageViewModel that matches the expected signature.\r\n  at Microsoft.Xaml.Interactions.Core.CallMethodAction.Execute(Object sender, Object parameter)\r\n at Microsoft.Xaml.Interactivity.Interaction.ExecuteActions(Object sender, ActionCollection actions, Object parameter)\r\n  at Microsoft.Xaml.Interactions.Core.EventTriggerBehavior.OnEvent(Object sender, Object eventArgs)"  string

I used the signature that was generated in the code behind. The ContainerContentChangingis fired in the ViewModel As you can see commented out I tried with just object too.

What is the correct signature?

XAML

<GridView x:Name="GvNewPlayList"
                      RelativePanel.Below="CbPlayListEditor"
                      Visibility="{Binding LbNewPlayListVisibility}"
                      Background="BurlyWood"
                      Padding="5"
                      Header="New Play List"
                      ItemsSource="{Binding NewLocalSoundsPlayListsSelectedItem.LocalSfxV2s}"

                      CanDragItems="True"
                      AllowDrop="True"
                      CanReorderItems="True"
                      IsItemClickEnabled="True"
                      DragItemsStarting="LbNewPlayList_OnDragItemsStarting"

                      DragOver="LbNewPlayList_OnDragOver">                   
                <interactivity:Interaction.Behaviors>
                    <core:EventTriggerBehavior EventName="Drop">
                        <core:CallMethodAction MethodName="GvNewPlayList_OnDrop"
                                               TargetObject="{Binding Mode=OneWay}" />
                    </core:EventTriggerBehavior>

                    <core:EventTriggerBehavior EventName="ContainerContentChanging">
                        <core:CallMethodAction MethodName="GvLocalSoundsPlayListEditorContainerContentChangingAsync"
                                               TargetObject="{Binding Mode=OneWay}" />
                    </core:EventTriggerBehavior>
                </interactivity:Interaction.Behaviors>

                <GridView.ItemTemplate>
                    <DataTemplate>
[...]

PlayPageViewModel

Exception fired on XAML attempting to target this method in the vm.

    // private async void GvNewPlayList_OnDrop(object sender, object e)
    // private async void GvNewPlayList_OnDrop()

    private async void GvNewPlayList_OnDrop(object sender, DragEventArgs e)
    {
        e.AcceptedOperation = DataPackageOperation.Copy;
        Logger.Log(this, "yup");
        [...]
    }

This one fires from the ContainerContentChanging event.

    public async void GvLocalSoundsPlayListEditorContainerContentChangingAsync()
    {
        Logger.Log(this, $"GvLocalSoundsPlayListEditorContainerContentChangingAsync: {SelectedPlayList?.PlayListName}");
        //_settings.CurrentPlayList = SelectedPlayList;
        //LocalSounds = await _theLolFxV2DataServices.GetPlayListAsync(SelectedPlayList);
        //NewLocalSoundsPlayListItems = await _theLolFxV2DataServices.GetPlayListAsync(CbPlayListEditorSelectedItem);
    }

Solution

  • When using a CallMethodAction for invoking a method, the signature of the method should be like this: public void DoSomthing(). The reasons for the exception are:

    1. GvNewPlayList_OnDrop is marked as private, it need mark as public;

    2. It cannot contain any parameters.

    So just modify its signature like that of the second method: public async void GvLocalSoundsPlayListEditorContainerContentChangingAsync()