나는 다음과 같은 XAML 내보기 모델의 삭제 명령에 결합하기 위해 노력하고있다 : 나는 그래서 프로그래밍 사용할 수있는 C#으로 변환하기 위해 노력하고있어자 마린은 XAML ContextAction가 ViewCell
<TextCell.ContextActions>
<MenuItem Command="{Binding Path=BindingContext.DeleteCollectionCommand, Source={x:Reference Name=CollectionListView}}"
CommandParameter="{Binding .}"
Text="Delete"
IsDestructive="True" />
</TextCell.ContextActions>
그것.
다음을 시도했지만 작동하지 않습니다. 무엇을 변경해야합니까? ViewModel DeleteCommand에 액세스하는 더 나은/다른 방법이 있습니까?
protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
var deleteAction = new MenuItem { Text = "Delete", IsDestructive = true }; // red background
deleteAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
deleteAction.SetBinding(MenuItem.CommandProperty,
new Binding("BindingContext.DeleteCommand", BindingMode.Default, null, null, null, "{x:Reference Name=CollectionBeerListView}"));
ContextActions.Add(deleteAction);
}
편집 내가 부모보기에서이 같은 셀을 SKAR의 답변을 결합하고 초기화하여이 작업을 얻을 수 있었다
:
lstView.ItemTemplate = new DataTemplate(() =>
{
var cell = new DeleteGenericListItemTemplate(page);
return cell;
});
이 이상적입니다 확실하지. 하지만 계속 움직여.
그럼 내가 할 바인딩 스로우 만드는 법을 모른다. Xaml을 사용하는 C#은 훨씬 쉽고 직선적인데, 내가 본 이상한 바인딩이라고해야한다. 질문의 두 번째 부분을 도와 드릴 수 있습니다. viewmodel에 필요한 속성에 도달하려면 BindingContext = new (your_ViewModel)을 설정해야합니다. 그렇게하면 쉽게 바인딩 할 수 있습니다. 더 잘 도와 드릴 수 있도록 코드 숨김 및 Xaml을 더 많이 사용할 수 있습니까? Xaml 대신 C#으로 왜이 작업을 원하십니까? – BraveHeart
내가 프로그래밍 방식으로 표시/숨기기 삭제 동작을 할 수 있어야합니다. C#에서이 작업을 수행하고 있습니다. 이것은 여러 장소에서 사용하고있는 일반 뷰 셀입니다. – aherrick
주어진 View Cell 컨텍스트 내에서 View Model의 "Delete Command"에 액세스해야합니다. – aherrick