C# 获取调用事件的 SwipeView Item/Object

C# Getting SwipeView Item/Object that invoked event

抱歉,新来的。我有一个对象的 CollectionView 和那里的字段,当我使用 SwipeView 调用删除事件时,我希望能够使用被选择的对象传递到 SQLite 查询以从数据库中删除该对象.我最初的计划是使用对象的 Id 来删除它,但我在这样做时遇到了麻烦。除了获取对象的属性,我还可以使用对象本身吗?

XAML

                    <SwipeView>
                        <SwipeView.RightItems>
                            <SwipeItems SwipeBehaviorOnInvoked="RemainOpen">
                                <SwipeItem Text="Delete" BackgroundColor="DarkGray" 
                                           Invoked="DeleteItem_Invoked"
                                           BindingContext="{Binding ID}">
                                </SwipeItem>
                            </SwipeItems>
                        </SwipeView.RightItems>

SQL

    public Task<int> DeleteBird(Bird bird)
    {
        return _database.DeleteAsync(bird);
    }

C#
    private void DeleteItem_Invoked(object sender, EventArgs e)
    {
        
        var swipeview = sender as SwipeItem;
        var id = swipeview.BindingContext;
        Database.DeleteBird(id); 
        Debug.WriteLine(id);
    }

Github

使用CommandParameter(不设置BindingContext

<SwipeItem Invoked="DeleteItem_Invoked" CommandParameter="{Binding .}" />

然后在事件处理程序中

private void DeleteItem_Invoked(object sender, EventArgs e)
{
    var swipeview = sender as SwipeItem;
    var item = (MyClassName)swipeview.CommandParameter;
    
    // item should be the selected item
}