pass parameter listview relaycommand RRS feed

  • Question

  • Hello,

    I get a cast error when trying to send my selected listviewitem with RelayCommand. I'm using the galasoft mvvm RelayCommand.


    System.InvalidCastException: Unable to cast object of type 'Windows.UI.Xaml.Controls.ItemClickEventArgs' to type 'utmaningen.Models.CatModel'.
       at GalaSoft.MvvmLight.Command.RelayCommand`1.Execute(Object parameter)
       at Microsoft.Xaml.Interactions.Core.InvokeCommandAction.Execute(Object sender, Object parameter)
       at Microsoft.Xaml.Interactivity.Interaction.ExecuteActions(Object sender, ActionCollection actions, Object parameter)
       at Microsoft.Xaml.Interactions.Core.EventTriggerBehavior.OnEven


    <Core:InvokeCommandAction Command="{Binding RelayCmd}"
                                                  CommandParameter="{Binding ElementName=CatsListview, Path=SelectedCat}"/>


    private RelayCommand<CatModel> _executeRelayCmd;
            public RelayCommand<CatModel> RelayCmd
                    return _executeRelayCmd?? (_executeRelayCmd= new RelayCommand<CatModel>(ExecuteCatCommand));

    public void ExecuteCatCommand(CatModel _executeRelayCmd)
    //Want to get my listview selection info.

    Sunday, June 22, 2014 2:33 PM


All replies

  • I would advise asking the Galasoft people about this.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, June 23, 2014 1:48 PM
  • Thanks,

    I solved this by getting the itemclick event args instead.

    Monday, June 23, 2014 4:05 PM