Prism Xamarin.Forms EventToCommandBehavior 使应用程序崩溃

Prism Xamarin.Forms EventToCommandBehavior crash the application

我正在尝试在 ListView 中使用 Xamarin.Forms 中的 prism 命令,但是一旦我引入 "ListView.Behaviors",应用程序就会崩溃并产生错误 "Unfortunately, App1.Droid has stopped".

该应用程序是一个非常小的演示,仅用于测试 Prism 中的命令。该页面在没有 "ListView.Behaviors".

的情况下工作正常

XAML代码如下

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             prism:ViewModelLocator.AutowireViewModel="True"
             x:Class="Intro.Views.Example03"
             xmlns:b="clr-namespace:Prism.Behaviors;assembly=Prism.Forms"
             Title="{Binding Title}">
  <ListView ItemsSource="{Binding ContactList}">
    <ListView.Behaviors>
      <b:EventToCommandBehavior EventName="ItemTapped" Command="{Binding ItemTappedCommand}" />
    </ListView.Behaviors>
    <ListView.ItemTemplate>
      <DataTemplate>
        <ViewCell>
          <StackLayout Orientation="Horizontal">
            <Label Text="{Binding Id}" HorizontalOptions="Center" VerticalOptions="Center" FontSize="Large" />
            <StackLayout Orientation="Vertical">
              <Label Text="{Binding FirstName}" HorizontalOptions="FillAndExpand" />
              <Label Text="{Binding LastName}" HorizontalOptions="FillAndExpand" />
              <Label Text="{Binding Email}" HorizontalOptions="FillAndExpand" />
            </StackLayout>
          </StackLayout>
        </ViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>
</ContentPage>

后面的代码是

public class Example03ViewModel : BindableBase, INavigationAware
{
    public ICommand ItemTappedCommand
    {
        get { return _itemTappedCommand; }
        set { SetProperty(ref _itemTappedCommand, value); }
    }

    private ICommand _itemTappedCommand;

    public Example03ViewModel()
    {
        _itemTappedCommand = new Command(ShowDetails);
    }

    private void ShowDetails(object obj)
    {
    }
}

我做错了什么?

EventToCommandBehavior 在 6.2 上不可用。它将在下一个预览版中提供。现在,您应该查看最新的 6.3 预览版。

https://github.com/PrismLibrary/Prism/wiki/Release-Notes-6.3.0-Pre1