Ich versuche, Kontextaktionen auf meiner Liste in Xamarin Forms zu implementieren, kann sie aber nicht ausführen. Ich verwende nicht XAML, sondern mein Layout im Code. Ich versuche, die Schritte in https://developer.xamarin.com/guides/xamarin-forms/user-interface/listview/interactivity/#Context_Actions zu folgen, und ich möchte eine neue Seite drücken, wenn "Bearbeiten" angeklickt wird.Implementieren von Xamarin Forms-Kontextaktionen
Ich räumte meinen Code auf und entfernte meine schwachen Versuche, Dinge zum Laufen zu bringen.
Das ist also meine benutzerdefinierte Liste Zelle:
public class PickerListCell : TextCell
{
public PickerListCell()
{
var moreAction = new MenuItem { Text = App.Translate ("Edit") };
moreAction.SetBinding (MenuItem.CommandParameterProperty, new Binding ("."));
moreAction.Clicked += async (sender, e) => {
var mi = ((MenuItem)sender);
var option = (PickerListPage.OptionListItem)mi.CommandParameter;
var recId = new Guid (option.Value);
// This is where I want to call a method declared in my page to be able to push a page to the Navigation stack
};
ContextActions.Add (moreAction);
}
}
Und hier ist mein Modell:
public class OptionListItem
{
public string Caption { get; set; }
public string Value { get; set; }
}
Und dies ist die Seite:
public class PickerPage : ContentPage
{
ListView listView { get; set; }
public PickerPage (OptionListItem [] items)
{
listView = new ListView() ;
Content = new StackLayout {
Children = { listView }
};
var cell = new DataTemplate (typeof (PickerListCell));
cell.SetBinding (PickerListCell.TextProperty, "Caption");
cell.SetBinding (PickerListCell.CommandParameterProperty, "Value");
listView.ItemTemplate = cell;
listView.ItemsSource = items;
}
// This is the method I want to activate when the context action is called
void OnEditAction (object sender, EventArgs e)
{
var cell = (sender as Xamarin.Forms.MenuItem).BindingContext as PickerListCell;
await Navigation.PushAsync (new RecordEditPage (recId), true);
}
}
Wie Sie sehen können, Meine Kommentare im Code habe ich angegeben, wo ich glaube, dass Dinge fehlen.
Bitte assistieren Sie Jungs! Danke!