Passing a parameter using RelayCommand defined in the ViewModel (from Josh Smith example)

后端 未结 6 514
既然无缘
既然无缘 2020-12-09 02:57

I would like to pass a parameter defined in the XAML (View) of my application to the ViewModel class by using the RelayCommand. I followed Josh Smith\'s excellent article o

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-09 03:25

    I don't understand why you have the extra complexity of specifying the lambda in the first place. Why not just do this:

    if (_aCommandWithAParameter == null)
    {           
        _aCommandWithAParameter = new RelayCommand(CommandWithAParameter);
    }
    
    private void CommandWithAParameter(object state)
    {
        var str = state as string;
    }
    
        

    提交回复
    热议问题