【发布时间】:2021-11-05 05:26:03
【问题描述】:
我在页面上有一组视觉元素,其中任何一个都可以长按。在代码中,我可以在长按按钮时运行命令:
for (int i = 0; i < choiceButtons.Length; i++)
{
TouchEffect.SetLongPressCommand(choiceButtons[i], new Command( async () =>
{
// Do stuff here, depending which button was long-pressed
}));
TouchEffect.SetLongPressCommandParameter(choiceButtons[i], choiceButtons[i].Text);
}
但是,我需要能够确定哪个视觉元素是被长按的元素。有没有办法做到这一点?
(视觉元素是 Grid 的子类。)
[编辑:索引已更正]
【问题讨论】:
-
使用命令参数
-
@Jason CommandParameter 将一个视觉元素作为其第一个参数,但我们不知道哪个视觉元素是鸡和蛋?
-
也将 VisualElement 作为第二个参数传递
-
@Jason 谢谢 - 会检查的。
-
将
choiceButtons[i].Text替换为choiceButtons[i]。
标签: xamarin.forms xamarin-community-toolkit