您只需创建一个自定义视图单元格:
public class MyCell : ViewCell
{
public MyCell ()
{
var button1 = new Button {Text = "Button 1"};
button1.Clicked += (sender1, e1) => {
// Action for button 1
};
var button2 = new Button {Text = "Button 2"};
button2.Clicked += (sender, e) => {
// Action for Button 2
};
View = new StackLayout
{
Orientation = StackOrientation.Horizontal,
Children = {
button1,
button2,
}
};
View.GestureRecognizers.Add(new TapGestureRecognizer());
}
}
最后一个TapGestureRecognizer是为了避免触摸的选择(和Android显示) .
并将其集成到ListView中
public DemoPage ()
{
var listView = new ListView
{
ItemsSource = new[] {"cell 1", "cell 2", "cell 3", "cell 4"},
ItemTemplate = new DataTemplate(typeof (MyCell))
};
Content = listView;
}
您还可以将按钮单击绑定到命令
Copyright © 广州京杭网络科技有限公司 2005-2024 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有