【发布时间】:2020-07-09 13:57:08
【问题描述】:
我的 Xamarin 表单应用程序中的 SwipeView 有问题。
我在 CollectionView 中有一个 SwipeView。 CollectionView 位于 StackLayout 内部,而 StackLayout 位于 Stacklayout 内部的 ScrollView 内部。
<ScrollView Margin="10,5,10,5" x:Name="MyViewList">
<StackLayout>
<Frame BorderColor="Teal">
<StackLayout>
<Label Text="Deine Vokabel" HorizontalTextAlignment="Center" FontSize="Large" TextColor="Teal"/>
<CollectionView x:Name="VList">
<CollectionView.ItemTemplate>
<DataTemplate>
<SwipeView>
<SwipeView.LeftItems>
<SwipeItems>
<SwipeItem Text="Delete" BackgroundColor="LightPink"/>
<SwipeItem Text="Edit" BackgroundColor="LightGreen"/>
</SwipeItems>
</SwipeView.LeftItems>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition
Width="*"
/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition
Height="*"
/>
</Grid.RowDefinitions>
<BoxView Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" BackgroundColor="Teal" HeightRequest="1" VerticalOptions="End" HorizontalOptions="FillAndExpand"/>
<Label Grid.Row="1" Grid.Column="0" Text="Number:" FontAttributes="Bold"/>
<Label Grid.Row="1" Grid.Column="1" Text="{Binding MyBinding}"/>
<Label Grid.Row="2" Grid.Column="0" Text="MYText:" FontAttributes="Bold"/>
<Label Grid.Row="2" Grid.Column="1" Text="{Binding MyBinding}"/>
<Label Grid.Row="3" Grid.Column="0" Text="MyText:" FontAttributes="Bold"/>
<Label Grid.Row="3" Grid.Column="1" Text="{Binding MyBinding}"/>
<Label Grid.Row="4" Grid.Column="0" Text="MyText1:" FontAttributes="Bold"/>
<Label Grid.Row="4" Grid.Column="1" Text="{Binding MyBinding}"/>
<Label Grid.Row="5" Grid.Column="0" Text="MyText2:" FontAttributes="Bold"/>
<Label Grid.Row="5" Grid.Column="1" Text="{Binding MyBinding}"/>
<Label Grid.Row="6" Grid.Column="0" Text="MyText:" FontAttributes="Bold"/>
<Label Grid.Row="6" Grid.Column="1" Text="{Binding MyBinding}"/>
<BoxView Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2" BackgroundColor="Teal" HeightRequest="1" VerticalOptions="End" HorizontalOptions="FillAndExpand"/>
</Grid>
</SwipeView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
</Frame>
</StackLayout>
</ScrollView>
如果我在 Android 上运行我的应用程序(目前尚未测试 iOS),我会收到此错误:
07-09 15:45:28.131 D/Mono (28233):请求加载参考 4 (共 6 个)的 /storage/emulated/0/Android/data/MyApp/files/.覆盖/Xamarin.Android.Support.v7.RecyclerView.dll 07-09 15:45:28.132 D/Mono (28233): 加载参考 4 /storage/emulated/0/Android/data/MyApp/files/.覆盖/Xamarin.Android.Support.v7.RecyclerView.dll asmctx DEFAULT,寻找 Xamarin.Android.Support.CustomView, 版本=1.0.0.0,文化=中性,PublicKeyToken=null 07-09 15:45:28.132 D/Mono (28233):程序集参考地址 Xamarin.Android.Support.v7.RecyclerView[0x7a3866a480] -> Xamarin.Android.Support.CustomView [0x7a47e79a80]:2 System.Reflection.TargetInvocationException: '调用目标抛出异常。'
这是调试中断的截图:
我使用 Xamarin.Forms 4.7 和 VisualStudio 2019。
我错过了什么?资源中的东西? SwipeView 不能在 ScrollView 中工作吗?
【问题讨论】:
-
首先,您需要查看 InnerException 属性以确定根本原因是什么
-
我该怎么做?
-
使用调试器检查异常对象
-
我知道如何调试,但我没有来或得到这个内部异常。后面的代码工作正常,只是可视化不工作
-
你得到一个应该包含 Exception 对象的异常。该对象有一个 InnerException 属性,该属性将包含根本原因的详细信息
标签: android xamarin xamarin.forms