Xamarin 如何在视图模型命令方法中获取手势识别器命令的参数?
我有一个模板,用于检查抽头:Xamarin 如何在视图模型命令方法中获取手势识别器命令的参数?,xamarin,xamarin.forms,Xamarin,Xamarin.forms,我有一个模板,用于检查抽头: <Grid.GestureRecognizers> <TapGestureRecognizer Command="{Binding TapCommand, Source={x:Reference this}}" CommandParameter="{Binding TapCommandParam, Source={x:Reference this}}" NumberOfTapsRequired="1" /> </Grid.G
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapCommand, Source={x:Reference this}}" CommandParameter="{Binding TapCommandParam, Source={x:Reference this}}" NumberOfTapsRequired="1" />
</Grid.GestureRecognizers>
我这样设置命令:
private ICommand openPageCmd;
public ICommand OpenPageCmd => openPageCmd ?? (openPageCmd = new Command(() => OpenPage()));
public void OpenPage()
{
// I need the parameter of the command here
}
private ICommand openPageCmd;
public ICommand OpenPageCmd => openPageCmd ?? (openPageCmd = new Command<string>((stringValue) => xx(stringValue)));
public void xx(string stringValue)
{
var a = 0;
}
当点击网格时,将调用命令,但如何访问参数,我想使用该参数如下声明您的命令:
private ICommand openPageCmd;
public ICommand OpenPageCmd => openPageCmd ?? (openPageCmd = new Command(() => OpenPage()));
public void OpenPage()
{
// I need the parameter of the command here
}
private ICommand openPageCmd;
public ICommand OpenPageCmd => openPageCmd ?? (openPageCmd = new Command<string>((stringValue) => xx(stringValue)));
public void xx(string stringValue)
{
var a = 0;
}
private ICommand和openPageCmd;
公共ICommand OpenPageCmd=>OpenPageCmd??(openPageCmd=new命令((stringValue)=>xx(stringValue));
公共void xx(字符串stringValue)
{
var a=0;
}
如下声明您的命令:
private ICommand openPageCmd;
public ICommand OpenPageCmd => openPageCmd ?? (openPageCmd = new Command(() => OpenPage()));
public void OpenPage()
{
// I need the parameter of the command here
}
private ICommand openPageCmd;
public ICommand OpenPageCmd => openPageCmd ?? (openPageCmd = new Command<string>((stringValue) => xx(stringValue)));
public void xx(string stringValue)
{
var a = 0;
}
private ICommand和openPageCmd;
公共ICommand OpenPageCmd=>OpenPageCmd??(openPageCmd=new命令((stringValue)=>xx(stringValue));
公共void xx(字符串stringValue)
{
var a=0;
}
在我的例子中,参数将是一个字符串。我对你的目标和你的目标有点困惑。你能告诉我该如何为这个案子定义你的目标吗?谢谢简单地用字符串替换它:)我将更新我的答案。感谢您的快速响应,我现在将尝试。在我的情况下,参数将是字符串。我对你的目标和你的目标有点困惑。你能告诉我该如何为这个案子定义你的目标吗?谢谢用字符串替换它:)我会更新我的答案。谢谢你的快速回复,我现在就试试。