我有这个XAML
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapGestureForUpdateCategories, Source={x:Reference MainPage}}" CommandParameter="false" />
</Label.GestureRecognizers>
以及我的 ViewModel 中的这段代码
public Command TapGestureForUpdateCategories => new Command(val =>
{
App.DB.UpdateAllCategoryGroups(val);
App.DB.UpdateAllCategory(val);
});
我试图从 XAML 传递参数 true 或 false,但在命令 C# 代码中,val 下有一行显示“无法从对象转换为 bool”。谁能帮我解决这个问题吗?
修改如下,我们可以通过TapGestureRecognizer.CommandParameter里面的x:type定义我们想要的类型
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapGestureForUpdateCategories, Source={x:Reference MainPage}}">
<TapGestureRecognizer.CommandParameter>
<x:Boolean>True</x:Boolean>
</TapGestureRecognizer.CommandParameter>
</TapGestureRecognizer>
</Label.GestureRecognizers>