我像这样绑定我的命令:
<Button Command="{Binding NextCommand}"
CommandParameter="Hello"
Content="Next" /> 在这里,我还绑定了它的CommandParameter属性,现在来看看如何从NextCommand中获取它的值。
public ICommand NextCommand
{
get
{
if (_nextCommand == null)
{
_nextCommand = new RelayCommand(
param => this.DisplayNextPageRecords()
//param => true
);
}
return _nextCommand;
}
}其函数定义:
public ObservableCollection<PhonesViewModel> DisplayNextPageRecords()
{
//How to fetch CommandParameter value which is set by
//value "Hello" at xaml. I want here "Hello"
PageNumber++;
CreatePhones();
return this.AllPhones;
}如何获取CommandParameter值?
提前谢谢。
发布于 2009-10-14 09:04:11
更改您的方法定义:
public ObservableCollection<PhonesViewModel> DisplayNextPageRecords(object o)
{
// the method's parameter "o" now contains "Hello"
PageNumber++;
CreatePhones();
return this.AllPhones;
}看看在创建RelayCommand时,它的“执行”lambda是如何接受参数的?将其传递到您的方法中:
_nextCommand = new RelayCommand(param => this.DisplayNextPageRecords(param));https://stackoverflow.com/questions/1565075
复制相似问题