gpt4 book ai didi

android - Xamarin.Forms 是否支持点击并按住手势?

转载 作者:行者123 更新时间:2023-11-29 01:17:55 25 4
gpt4 key购买 nike

我是 Xamarin.forms 的新手,我的客户想要一个像 Gmail 这样的功能,用户可以点击并按住其中一个列表项并获得多选项目的选项。

该应用程序将有一个项目列表,其中包含不同的可用选项,例如删除、查看、上传等。所以基本上它有 5 个选项,并且根据 Windows Mobile 限制,该应用程序不能有超过 4 个菜单选项(ToolbarItem)。因此需要点击并按住手势。一旦用户点击并按住其中一项,ToolbarItem 应该更改并替换为仅删除选项。通过这样做,我们可以将 ToolbarItem 减少到四个。

任何引用资料都会有很大帮助!! :-)

还想知道点击并按住是否可行,那么不同平台(iOS、windows、android)将如何呈现它?它会由 Xamarin.forms 处理还是代码中有某些内容必须针对不同的操作系统平台处理?

最佳答案

您是否考虑过使用 Context Options而不是替换工具栏中的选项?

如果您可以使用上下文选项而不是工具栏,则不需要第 3 方组件,因为 Xamarin.Forms 允许您轻松地为每个 listView 项目定义此类选项:

实例化您的 ListView

var listView = new ListView();
listView.ItemTemplate = new DataTemplate(typeof(MyListItemCell));

数据模板应该是这样的:

public class MyListItemCell : ViewCell
{
// To register the LongTap/Tap-and-hold gestures once the item model has been assigned
protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
RegisterGestures();
}

private void RegisterGestures()
{
var deleteOption = new MenuItem()
{
Text = "Delete",
Icon = "deleteIcon.png", //Android uses this, for example
CommandParameter = ((ListItemModel) BindingContext).Id
};
deleteOption.Clicked += deleteOption_Clicked;
ContextActions.Add(deleteOption);

//Repeat for the other 4 options

}
void deleteOption_Clicked(object sender, EventArgs e)
{
//To retrieve the parameters (if is more than one, you should use an object, which could be the same ItemModel
int idToDelete = (int)((MenuItem)sender).CommandParameter;
//your delete actions
}
//Write the eventHandlers for the other 4 options
}

关于android - Xamarin.Forms 是否支持点击并按住手势?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34941373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com