我正在尝试在 c# 中执行按钮的命令。但这并没有发生。这是我尝试过的
Command = new Command(async () =>
{
var page = new NewPage2();
var inputEntry = page.FindByName<Entry>("inputEntry");
inputEntry.Text = item;
var button = page.FindByName<Button>("sendButton");
button.Command?.Execute(null);
await Application.Current.MainPage.Navigation.PushAsync(page);
})
如您所见,我创建了一个页面并获取该页面中的条目,并将文本(项目)放入条目中,直到这里一切正常,但是当我执行按钮命令发送它时,它不起作用,直到我单击它.
我找到了解决方案。我改变了
行button.Command?.Execute(null);
通过这条线
page.OnSendClickedAsync(button, EventArgs.Empty);
记住通过您在“Clicked”或“Command”中调用的方法来更改 OnSendClickedAsync,当然还有页面名称和按钮名称。
尽管尝试了提供的解决方案,但我遇到了与上述问题类似的问题。有人可以提供进一步的说明或帮助吗?