Dimitris
Dimitris

Reputation: 755

Prism Xamarin.Forms EventToCommandBehavior crash the application

I’m trying to use prism commands in Xamarin.Forms in a ListView but as soon as I introduce the "ListView.Behaviors", the application crashes producing the error "Unfortunately, App1.Droid has stopped".

The application is a very small demo just for testing commands in Prism. The page works fine without the "ListView.Behaviors".

The XAML code is the following

<?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>

and the code behind is

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)
    {
    }
}

What am I doing wrong?

Upvotes: 0

Views: 544

Answers (1)

user5420778
user5420778

Reputation:

EventToCommandBehavior is not available on 6.2. It will be available in the next preview release. For now, you should check out the latest 6.3 preview.

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

Upvotes: 1

Related Questions