views:

26

answers:

1

in VM, set ICommand like:

  private RelayCommand<EventArgs> _myCommand = null;
    public RelayCommand<EventArgs> MyCommand
    {
        get
        {
            if (_myCommand == null)
            {
                _myCommand = new RelayCommand<EventArgs>((e) =>
                {
                  //....
                }
                );                    
            }

            return _myCommand;
        }
    }

In xaml, binding to this command like

<Button Content="Test Command" Margin="2,0,2,0" Command="{Binding Path=MyCommand}" CommandParameter="{Binding ElementName=InputTextBox, Path=Text}" />

then run the app. it say can't convert string to EventArgs.

How to set EventArgs for ICommand binding?

A: 

I'm not familiar with RelayCommand<T> I've only come across RelayCommand.

However it would seem that RelayCommand<EventArgs> can't possibly be useful. I suspect that you would at least need RelayCommand<string>.

AnthonyWJones
Thank you. Yes, I tried RelayCommand<string> for this issue as the solution. Seems fine.
KentZhou