XF 表视图添加和删除行
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
namespace App31
{
public partial class App : Application
{
TableSection tableSection;
public App ()
{
InitializeComponent();
var textCell = new TextCell
{
Text = "TextCell Text",
Detail = "TextCell Detail"
};
namespace App31
{
public partial class App : Application
{
TableSection tableSection;
public App ()
{
InitializeComponent();
var textCell = new TextCell
{
Text = "TextCell Text",
Detail = "TextCell Detail"
};
var entryCell = new EntryCell
{
Label = "EntryCell",
Placeholder = "Default Keyboard",
Keyboard = Keyboard.Default
};
{
Label = "EntryCell",
Placeholder = "Default Keyboard",
Keyboard = Keyboard.Default
};
tableSection = new TableSection("Table Section 1")
{
textCell,entryCell
};
var tableView = new TableView
{
Intent = TableIntent.Settings,
Root = new TableRoot("Table Title")
{
tableSection
}
};
MainPage = new ContentPage
{
Content = tableView
};
var addAction = new MenuItem {Text= "插入操作" };
var delAction = new MenuItem {Text= "删除操作" };
addAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
delAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
textCell.ContextActions.Add(addAction);
textCell.ContextActions.Add(delAction);
addAction.Clicked += AddAction_Clicked;
delAction.Clicked += DelAction_Clicked;
}
{
textCell,entryCell
};
var tableView = new TableView
{
Intent = TableIntent.Settings,
Root = new TableRoot("Table Title")
{
tableSection
}
};
MainPage = new ContentPage
{
Content = tableView
};
var addAction = new MenuItem {Text= "插入操作" };
var delAction = new MenuItem {Text= "删除操作" };
addAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
delAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
textCell.ContextActions.Add(addAction);
textCell.ContextActions.Add(delAction);
addAction.Clicked += AddAction_Clicked;
delAction.Clicked += DelAction_Clicked;
}
private void DelAction_Clicked(object sender, EventArgs e)
{
tableSection.RemoveAt(tableSection.Count - 1);
}
{
tableSection.RemoveAt(tableSection.Count - 1);
}
private void AddAction_Clicked(object sender, EventArgs e)
{
var swithCell = new SwitchCell
{
Text = "SwitchCell",
On = true
};
tableSection.Add(swithCell);
}
{
var swithCell = new SwitchCell
{
Text = "SwitchCell",
On = true
};
tableSection.Add(swithCell);
}
protected override void OnStart ()
{
// Handle when your app starts
}
{
// Handle when your app starts
}
protected override void OnSleep ()
{
// Handle when your app sleeps
}
{
// Handle when your app sleeps
}
protected override void OnResume ()
{
// Handle when your app resumes
}
}
}
{
// Handle when your app resumes
}
}
}