传单个参数的话在xaml用     Command={Binding ViewModel的事件处理名称}    CommandParameter={Binding 要传递的控件名称}

ViewModel的事件处理

public ICommand btn_Click

get{

  return new RelayCommand<Button>((p)=>

  {

      //处理代码

  });

}

}

多个参数传递:

在xaml用     Command={Binding ViewModel的事件处理名称}

xaml页面后台:

viewmodel对象.txtName=txtName; 

viewmodel对象.txtPassword=txtPassword;......

this.DataContext=viewmodel对象

 

viewmodel  里面定义全局变量和要传递的控件类型相同public TextBox txtName{get;set;}public TextBox txtPassword{get;set;}

事件处理:

public ICommand btn_Click

get{

  return new RelayCommand(()=>{

    //处理代码

 

  });

}

}

 

如果需要事件的参数(sender,e)的话,

Command={Binding ViewModel的事件处理名称}

   CommandParameter={Binding 要传递的控件名称}

ViewModel代码如下:

public ICommand btn_Click

get{

  return new RelayCommand<Button>((p)=>

  {

    p.Click+=(sender,e)=>{

      //处理代码

     };

  });

}

}

 

WPF、AE技术交流群:94234450  
点击加入QQ群:mvvm框架下页面与ViewModel的各种参数传递方式

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2021-11-17
  • 2021-10-24
猜你喜欢
  • 2021-12-13
  • 2021-10-28
  • 2022-12-23
  • 2021-06-03
  • 2022-02-28
  • 2022-12-23
相关资源
相似解决方案