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

时间:2017-02-08 10:05:01

标签: xamarin.forms prism

我正在尝试在ListView中的Xamarin.Forms中使用prism命令但是只要我引入" ListView.Behaviors",应用程序崩溃就会产生错误"不幸的是,App1。 Droid已经停止了#34;。

该应用程序是一个非常小的演示,仅用于测试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)
    {
    }
}

我做错了什么?

1 个答案:

答案 0 :(得分:1)

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

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