Xamarin Forms에서 내 목록에 컨텍스트 작업을 구현하려고하는데 작동하지 않습니다. XAML을 사용하지 않고 대신 코드에서 레이아웃을 만듭니다. https://developer.xamarin.com/guides/xamarin-forms/user-interface/listview/interactivity/#Context_Actions의 단계를 따르려고하고 있으며 "편집"을 클릭하면 새 페이지를 보내려고합니다.Xamarin Forms 컨텍스트 작업 구현
제 코드를 정리하고 제 기능을 작동시키기위한 약한 시도를 제거했습니다.
그래서이 내 사용자 지정 목록 세포입니다 :
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);
}
}
그리고 여기 내 모델 :
public class OptionListItem
{
public string Caption { get; set; }
public string Value { get; set; }
}
그리고 이것은 페이지입니다 : 당신이에서 볼 수 있듯이
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);
}
}
코드에서 내 의견, 내가 어디에 물건이 실종 있다고 믿는 지적했다.
제발 도와주세요! 감사합니다.