【发布时间】:2023-02-14 06:40:45
【问题描述】:
我有以下 XAML
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:LogEntry">
<SwipeView>
<SwipeView.RightItems>
<SwipeItem Text="Delete"
BackgroundColor="Orange"
Command="{Binding Source={RelativeSource AncestorType={x:Type viewModel:MainPageViewModel}}, Path=RemoveLogEntryCommand}"
CommandParameter="{Binding .}" />
<SwipeItem Text="Delete"
BackgroundColor="Red"
IsDestructive="True" />
</SwipeView.RightItems>
<Grid Padding="10">
<Frame HeightRequest="125"
Padding="0"
Style="{StaticResource CardView}">
<Frame.GestureRecognizers>
<TapGestureRecognizer CommandParameter="{Binding .}"
Command="{Binding Source={RelativeSource AncestorType={x:Type viewModel:MainPageViewModel}}, Path=GotoLogEntryDetailsCommand}" />
</Frame.GestureRecognizers>
<Grid Padding="0"
ColumnDefinitions="80,*">
使用社区工具包的以下 ICommand 声明
[RelayCommand]
private async Task GotoLogEntryDetails(LogEntry logEntry)
{
if (logEntry == null)
return;
await _appNavigationService.GoTo($"{nameof(LogEntryDetailsPage)}", true,
new Dictionary<string, object>
{
{ "LogEntry", logEntry }
});
}
[RelayCommand]
private async Task RemoveLogEntry(LogEntry logEntry)
{
}
如果我在 RemoveLogEntry 中放置一个断点,然后单击我的删除按钮,则永远不会到达断点。如果我将 RemoveLogEntry 放在点击手势上并点击我的项目,然后到达断点,所以我知道代码生成器已经创建了一个有效的 ICommand。
Intellisense 告诉我CommandParameter . 上的参数实际上是一个 LogEntry,因此我需要声明 viewModel 类型。
SwipeItem 的祖先绑定路径有什么问题?
【问题讨论】: