【发布时间】:2016-03-01 14:21:00
【问题描述】:
如何在我的笔记列表应用程序中添加滑动以删除。我正在使用 xamarin 表单。我在 xamarin 表单示例中搜索过,但找不到它。我还尝试了使用 menuItem 等的列表视图性能选项,但我不知道如何在我的代码中进行调整。任何人都可以帮我解决这个问题吗? 我的代码如下:
public partial class MyPage
{
List<Note> notes;
string NotesFile {
get {
var documents = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
return System.IO.Path.Combine (documents, "notes.json");
}
}
public MyPage()
{
BuildContent();
LoadNotes ();
ReloadListContents ();
AddNoteButton.Clicked += (sender, args) => {
var note = new Note("typ...");
notes.Add(note);
EditNote(note);
};
NoteListView.ItemTapped += (sender, row) =>
{
NoteListView.SelectedItem = null;
Note note = (Note)row.Item;
EditNote(note);
};
buttonDelete.Clicked += (sender, args) =>{
notes.RemoveAt(0);
DisplayAlert("Delete", "Row deleted", "OK");
};
}
} 我的页面.cs
{
public ListView NoteListView = new ListView ();
public Button AddNoteButton;
public Button buttonDelete;
private void BuildContent()
{
AddNoteButton = new Button
{
Text = "Add New Note",
TextColor = Color.White,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
buttonDelete = new Button
{
Text = "Delete Note ",
TextColor = Color.White,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
Content = new StackLayout
{
BackgroundColor = Color.Black,
Children = {
new Label {
Text = "Note Taker",
TextColor = Color.White
},
NoteListView,
AddNoteButton,
buttonDelete
}
};
}
【问题讨论】:
-
这些只是代码的一部分。
-
谢谢。但我试过这个。我如何在我的代码中调整它。我没有使用 TextCell 所以 contextActions 将不起作用。还有其他安排吗?
-
@preet,上下文动作是 View Cell 类的一部分,如果你想拥有这种能力,你需要使用 View Cell,否则添加滑动手势识别器可能会起作用。可能是这样的arteksoftware.com/gesture-recognizers-with-xamarin-forms
标签: c# json xamarin-forms