我正在尝试从ListView
中删除项目/行,但困难在于我还需要传递一些委托或触发某些事件之类的东西,因此当人们点击按钮以删除该行时,我的代码会处理其他逻辑(例如从数据库中删除该项等)。
我有一个自定义控件:
public class SportsTeam : StackLayout { .. }
在这个控件中,其中一个元素是一个ListView
,它列出了运动队中的所有人。
var viewModel = teamMembers.Select(x => new SportsTeamViewModel(x));
return new ListView
{
HasUnevenRows = true,
ItemSource = viewModel,
ItemTemplate = new DataTemplate(typeof(SportsTeamViewCell));
};
在 SportsTeamViewCell
中,我有以下内容:
private Grid CreateContent()
{
var grid = new Grid();
// Setup row and column definitions.
// Add items to the Grid
grid.Children.Add(...);
var removeButton = RemoveButton;
grid.Children.Add(removeButton);
Grid.SetRowSpan(removeButton, 2);
return grid;
}
private Button RemoveButton
{
get
{
var button = new Button
{
Image = "Icons/remove.png"
};
return button;
}
}
从这里开始,我不知道如何使按钮触发事件或通过构造函数传递一些删除内容,以便对要删除的单元格/行/项执行一些自定义逻辑。
Id
、UserName
或其他任何东西... - Pure.Krome