XAML> ViewModel命令参数-无法从对象转换为布尔值? [英] XAML > ViewModel Command parameter - Cannot convert from object to bool?

查看:42
本文介绍了XAML> ViewModel命令参数-无法从对象转换为布尔值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个XAML

<Label.GestureRecognizers>
   <TapGestureRecognizer Command="{Binding TapGestureForUpdateCategories, Source={x:Reference MainPage}}" CommandParameter="false" />
</Label.GestureRecognizers>

以及此代码在我的ViewModel中

and this code in my ViewModel

public Command TapGestureForUpdateCategories => new Command(val =>
{
    App.DB.UpdateAllCategoryGroups(val);
    App.DB.UpdateAllCategory(val);
});

我正在尝试从XAML传递参数true或false,但是在命令C#代码中val下有一行,写着无法从对象转换为布尔值".有人可以帮我吗?

I am trying to pass the parameter true or false from the XAML but in the command C# code there is a line under val saying "Cannot convert from object to bool". Can anyone help me with this?

推荐答案

进行如下修改,我们可以通过TapGestureRecognizer.CommandParameter

Modify as below , we can define the type we want by x:type inside TapGestureRecognizer.CommandParameter

<Label.GestureRecognizers>
    <TapGestureRecognizer Command="{Binding TapGestureForUpdateCategories, Source={x:Reference MainPage}}">
        <TapGestureRecognizer.CommandParameter>
            <x:Boolean>True</x:Boolean>
        </TapGestureRecognizer.CommandParameter>
    </TapGestureRecognizer>
</Label.GestureRecognizers>

这篇关于XAML&gt; ViewModel命令参数-无法从对象转换为布尔值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆