[英]How to Pass parameter to a Command in MVVM
View: <Button Command="{Binding GetChangeLogCommand}"
查看:
<Button Command="{Binding GetChangeLogCommand}"
ViewModel: GetChangeLogCommand = new DelegateCommand(GetChangeLog);
ViewModel:
GetChangeLogCommand = new DelegateCommand(GetChangeLog);
Method: 方法:
public ICommand GetChangeLogCommand { get; set; }
private async void GetChangeLog(bool isLatest)
{
// code goes here . . .
}
I'm going to use GetChangeLogCommand
multiple time and pass boolean parameter is it possible with MVVM sorry I'm new with this. 我将多次使用
GetChangeLogCommand
并通过布尔参数传递MVVM是否可以,抱歉,我是新来的。
If you are that particular to pass the button element to viewmodel You can use below code : 如果您特别希望将button元素传递给viewmodel,则可以使用以下代码:
CommandParameter="{Binding ElementName=YourButtonName}"
You could even pass the entire window, user control, or a particular list or list item to the view model 您甚至可以将整个窗口,用户控件或特定的列表或列表项传递给视图模型。
CommandParameter="{Binding ElementName=YourWindow}"
CommandParameter="{Binding ElementName=Control}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.