Xaml System.Reflection.targetingException:&x27;调用的目标已引发异常;在列表视图中放置SwipeView时
我现在在Xamarin.Forms应用程序的编码中遇到问题。 我有一个带有StackLayout的列表视图(运行良好)。但当我看到SwipeView存在时,我更新到了Xamarin.Forms的最新版本(4.4.0.991640),并生成了以下xaml代码:Xaml System.Reflection.targetingException:&x27;调用的目标已引发异常;在列表视图中放置SwipeView时,xaml,xamarin,xamarin.forms,Xaml,Xamarin,Xamarin.forms,我现在在Xamarin.Forms应用程序的编码中遇到问题。 我有一个带有StackLayout的列表视图(运行良好)。但当我看到SwipeView存在时,我更新到了Xamarin.Forms的最新版本(4.4.0.991640),并生成了以下xaml代码: <StackLayout Grid.Row="0" Grid.Column="2" Grid.RowSpan="2" BackgroundColor="LightGray"> <L
<StackLayout Grid.Row="0" Grid.Column="2" Grid.RowSpan="2" BackgroundColor="LightGray">
<ListView x:Name="ItemsListView"
ItemsSource="{Binding Items}"
VerticalOptions="FillAndExpand"
HasUnevenRows="true"
RefreshCommand="{Binding LoadItemsCommand}"
IsPullToRefreshEnabled="true"
IsRefreshing="{Binding IsBusy, Mode=OneWay}"
CachingStrategy="RecycleElement"
ItemSelected="OnItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<SwipeView>
<SwipeView.RightItems>
<SwipeItems>
<SwipeItem Text="Favorite"
BackgroundColor="LightGreen"
Invoked="OnModifySwipeItemInvoked" />
<SwipeItem Text="Delete"
BackgroundColor="LightPink"
Invoked="OnDeleteSwipeItemInvoked" />
</SwipeItems>
</SwipeView.RightItems>
<SwipeView.Content>
<StackLayout Padding="10" BackgroundColor="{Binding ColorCode}">
<Label Text="{Binding Type}"
d:Text="{Binding .}"
LineBreakMode="NoWrap"
Style="{DynamicResource ListItemTextStyle}"
FontSize="Large"
HorizontalOptions="Center"/>
<Label Text="{Binding Description}"
d:Text="Item descripton"
LineBreakMode="NoWrap"
Style="{DynamicResource ListItemDetailTextStyle}"
FontSize="Medium"
HorizontalOptions="Center"/>
</StackLayout>
</SwipeView.Content>
</SwipeView>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
没有尝试捕获可能,因为它发生在我返回页面时,我尝试了未处理的异常,但仍然没有获得更多信息
如果你需要更多的信息,请问我。
你能帮帮我吗?谢谢
System.Reflection.TargetInvocationException:“调用的目标已引发异常。”
SwipeView
在Xamarin.Forms 4.4中提供。但是,它目前是实验性的,在调用Forms.Init之前,只能将以下代码行添加到iOS上的AppDelegate
类、Android上的MainActivity
类或UWP上的App
类:
Forms.SetFlags("SwipeView_Experimental");
(如果否,将出现相同的错误。)
例如,在Android中:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
Forms.SetFlags("SwipeView_Experimental"); // Add here
global::Xamarin.Forms.Forms.Init (this, bundle);
LoadApplication (new App ());
}
}
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
Forms.SetFlags("SwipeView_Experimental"); // Add here
global::Xamarin.Forms.Forms.Init ();
LoadApplication (new App ());
return base.FinishedLaunching (app, options);
}
}
在iOS中:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
Forms.SetFlags("SwipeView_Experimental"); // Add here
global::Xamarin.Forms.Forms.Init (this, bundle);
LoadApplication (new App ());
}
}
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
Forms.SetFlags("SwipeView_Experimental"); // Add here
global::Xamarin.Forms.Forms.Init ();
LoadApplication (new App ());
return base.FinishedLaunching (app, options);
}
}
如果想了解更多信息,您可以查看此查看内部视图->输出以查找崩溃日志,您将找到实际应用程序崩溃的文件名行号及其原因。如果需要进一步帮助,请与他人分享,在该页面的InitializeComponent中添加一个try catch,以获取StackTrace,它将告诉您是哪行代码导致了此问题!