【问题标题】:How to Pass parameter to a Command in MVVM如何将参数传递给 MVVM 中的命令
【发布时间】:2016-10-30 04:01:40
【问题描述】:

查看:<Button Command="{Binding GetChangeLogCommand}"

ViewModel:GetChangeLogCommand = new DelegateCommand(GetChangeLog);

方法:

public ICommand GetChangeLogCommand { get; set; }
private async void GetChangeLog(bool isLatest)
{
    // code goes here . . .
}

我将多次使用GetChangeLogCommand 并传递布尔参数是否可以使用 MVVM 抱歉我是新手。

【问题讨论】:

标签: c# mvvm data-binding binding windows-store-apps


【解决方案1】:

如果您特别想将按钮元素传递给 viewmodel,您可以使用以下代码:

 CommandParameter="{Binding ElementName=YourButtonName}"

您甚至可以将整个窗口、用户控件或特定列表或列表项传递给视图模型

 CommandParameter="{Binding ElementName=YourWindow}"     
 CommandParameter="{Binding ElementName=Control}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-11
    • 2021-05-20
    • 1970-01-01
    • 2011-09-06
    • 2013-10-11
    • 1970-01-01
    相关资源
    最近更新 更多