【发布时间】: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