您是否考慮過使用Context Options而不是替換工具欄中的選項?
如果你可以使用右鍵選項,而不是工具欄,你不需要第三方組件,如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
}
如果我必須這樣做,每個平臺上,那麼這將意味着在Xamar 3個平臺上創建3個不同的項目在或修改xamarin.forms項目來實現它? – Arti
你能提供任何相同的例子或參考.. – Arti