C# 如何将参数传递给ICommand?
我定义了一个ICommand类ReadPersons,它使用特定的where子句从数据库中读取所有person对象 通过按下按钮执行命令,并在文本框中插入where子句 问题:如何将文本从文本框传递到Execute命令 MainWindow.xaml:C# 如何将参数传递给ICommand?,c#,wpf,xaml,C#,Wpf,Xaml,我定义了一个ICommand类ReadPersons,它使用特定的where子句从数据库中读取所有person对象 通过按下按钮执行命令,并在文本框中插入where子句 问题:如何将文本从文本框传递到Execute命令 MainWindow.xaml: <Button Command="{Binding ReadPersons}">Read persons</Button> <TextBox Name="textBoxWhereClause" /&g
<Button Command="{Binding ReadPersons}">Read persons</Button>
<TextBox Name="textBoxWhereClause" />
public void Execute(object parameter)
{
// Read all persons with my where-clause
string whereClause = ??? //todo
}
是的,你可以
<Button Command="{Binding ReadPersons}"
CommandParameter="{Binding Text, ElementName=textBoxWhereClause}">
Read persons</Button>
读书人
将在其ICommand方法中写入什么来捕获参数值?
<Button Command="{Binding ReadPersons}"
CommandParameter="{Binding Text, ElementName=textBoxWhereClause}">
Read persons</Button>