Prism Xamarin.Forms EventToCommandBehavior使应用程序崩溃
我正试图在ListView中的Xamarin.Forms中使用prism命令,但一旦引入ListView.Behaviors,应用程序就会崩溃,产生错误。不幸的是,App1.Droid已经停止 该应用程序是一个非常小的演示程序,仅用于在Prism中测试命令。没有ListView.Behaviors,页面工作正常 XAML代码如下所示Prism Xamarin.Forms EventToCommandBehavior使应用程序崩溃,xamarin.forms,prism,Xamarin.forms,Prism,我正试图在ListView中的Xamarin.Forms中使用prism命令,但一旦引入ListView.Behaviors,应用程序就会崩溃,产生错误。不幸的是,App1.Droid已经停止 该应用程序是一个非常小的演示程序,仅用于在Prism中测试命令。没有ListView.Behaviors,页面工作正常 XAML代码如下所示 <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamari
<?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>
我做错了什么?EventToCommandBehavior在6.2上不可用。它将在下一个预览版本中提供。现在,您应该查看最新的6.3预览版
您是否尝试改用DelegateCommand?是的,我尝试过,但结果相同您使用的是什么版本的Prism?我使用的是6.2.0包Prism.Forms,Prism.Unity.Forms,Prism.Core
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)
{
}
}