在XAML中,我正在执行以下操作:
<template:GridTemplate GridType="2"
Text="Answer Visible" Label="{Binding AtiLabel}"
TapCommand="{Binding OpenPageCmd }"
TapCommandParam="Answer Visible" />
,在C#中,我这样做:
var cell = new GridTemplate {
BindingContext = row,
GridType = "2",
Text = row.Name,
Label = "X",
TapCommand = vm.OpenPageCmd,
TapCommandParam = "Category"
};
但是在C#中,它给了我这个错误:
Cards.DetailsSection.cs(34,34):错误CS0266:无法隐式 将类型'System.Windows.Input.ICommand'转换为 'Xamarin.Forms.Command'。存在显式转换(您是 缺少演员表?)(CS0266)
有人可以提出解决方案并告诉我为什么可能会发生这种情况吗?
private ICommand openPageCmd;
public ICommand OpenPageCmd => openPageCmd ?? (openPageCmd = new Command<string>((pageType) => settingsPage.OpenPage(pageType)));
答案 0 :(得分:0)
您可以做几件事。将您的ICommand
更改为具体的Command
:
private Command openPageCmd;
public Command OpenPageCmd => openPageCmd ?? (openPageCmd = new Command<string>((pageType) => settingsPage.OpenPage(pageType)));
或者如果您创建的控件是template:GridTemplate
期望ICommand
。最后,您可以显式转换OpenPageCmd
命令:TapCommand = (Command)vm.OpenPageCmd,
。