【问题标题】:XAML > ViewModel Command parameter - Cannot convert from object to bool?XAML > ViewModel 命令参数 - 无法从对象转换为布尔值?
【发布时间】:2017-09-20 00:27:43
【问题描述】:

我有这个 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 下有一行说“无法从对象转换为布尔值”。谁能帮我解决这个问题?

【问题讨论】:

    标签: xamarin xamarin.forms


    【解决方案1】:

    修改如下,我们可以在 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>
    

    【讨论】:

      猜你喜欢
      • 2012-06-08
      • 2011-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-25
      • 1970-01-01
      • 2018-12-02
      • 1970-01-01
      相关资源
      最近更新 更多