【问题标题】:Prism Xamarin.Forms EventToCommandBehavior crash the applicationPrism Xamarin.Forms EventToCommandBehavior 使应用程序崩溃
【发布时间】:2017-02-09 04:49:31
【问题描述】:

我正在尝试在 ListView 中的 Xamarin.Forms 中使用 prism 命令,但是一旦我引入“ListView.Behaviors”,应用程序就会崩溃并产生错误“不幸的是,App1.Droid 已停止”。

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

我做错了什么?

【问题讨论】:

  • 您是否尝试改用DelegateCommand
  • 是的,我做了,但结果是一样的
  • 您使用的是哪个版本的 Prism?
  • 我使用的是 6.2.0(包 Prism.Forms、Prism.Unity.Forms、Prism.Core)

标签: xamarin.forms prism


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-20
    • 1970-01-01
    • 2019-01-22
    • 2019-06-02
    • 2020-10-25
    • 1970-01-01
    • 1970-01-01
    • 2019-02-19
    相关资源
    最近更新 更多