简体   繁体   中英

How to Pass parameter to a Command in MVVM

View: <Button Command="{Binding GetChangeLogCommand}"

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.

If you are that particular to pass the button element to viewmodel You can use below code :

 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}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM