I am binding my command like:
<Button Command="{Binding NextCommand}"
CommandParameter="Hello"
Content="Next" />
Here, I also bind its CommandParameter property, now how to fetch its value from NextCommand.
public ICommand NextCommand
{
get
{
if (_nextCommand == null)
{
_nextCommand = new RelayCommand(
param => this.DisplayNextPageRecords()
//param => true
);
}
return _nextCommand;
}
}
Its function definition:
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;
}
How to fetch CommandParameter value?
Thanks in advance.
Change your method definition:
public ObservableCollection<PhonesViewModel> DisplayNextPageRecords(object o)
{
// the method's parameter "o" now contains "Hello"
PageNumber++;
CreatePhones();
return this.AllPhones;
}
See how when you create your RelayCommand, its "Execute" lambda takes a parameter? Pass that into your method:
_nextCommand = new RelayCommand(param => this.DisplayNextPageRecords(param));