我使用Prism Library和Xamarin Forms并尝试使用EventToCommandBehavior描述here在Listview上附加ItemTapped行为。如何使用Xamarin Prism EventToCommand提取ListView项目行为
当ItemTappedCommand委托被执行时,事件参数为null,这意味着我无法提取ListView Item。
下面是我的ViewModel代码:
private DelegateCommand<ItemTappedEventArgs> _itemTappedCommand;
public RecipeListViewModel(INavigationService navigationService) : base(navigationService)
{
RefreshDataCommand = new Command(async() => await RefreshData());
_itemTappedCommand = new DelegateCommand<ItemTappedEventArgs>(args => {
var b = args; // args is null
_navigationService.NavigateAsync(nameof(Recipe));
});
}
public DelegateCommand<ItemTappedEventArgs> ItemTappedCommand { get { return _itemTappedCommand; } }
这是我的XAML
<ListView ItemsSource="{Binding Recipes}"
HasUnevenRows="false"
IsPullToRefreshEnabled="true"
CachingStrategy="RecycleElement"
IsRefreshing="{Binding IsBusy, Mode=OneWay}"
RefreshCommand="{Binding RefreshDataCommand}"
x:Name="lvRecipes">
<ListView.Behaviors>
<b:EventToCommandBehavior EventName="ItemTapped" Command="{Binding ItemTappedCommand}" />
</ListView.Behaviors>
<ListView.Header>..........
.....</ListView>
谢谢!我现在明白它是如何工作的。你的框架是一路炸弹...... –