Как решить "исключение было выброшено целью вызова" - PullRequest
0 голосов
/ 09 июля 2020

У меня проблема с SwipeView в моем приложении форм Xamarin.

У меня есть SwipeView внутри CollectionView. CollectionView находится внутри StackLayout, который находится внутри ScrollView, который находится внутри Stacklayout.

   <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/.override/Xamarin.Android.Support.v7.RecyclerView.dll asmctx DEFAULT, ищет Xamarin. Android .Support.CustomView, Version = 1.0.0.0, Culture = нейтральный, PublicKeyToken = null 07-09 15: 45: 28.132 D / Mono (28233): Ссылка на сборку addref Xamarin. Android .Support.v7.RecyclerView [0x7a3866a480] -> Xamarin. Android .Support.CustomView [0x7a47e79a80]: 2 System.Reflection.TargetInvocationException: 'Исключение было выдано целью вызова.'

Это скриншот t отладки:

введите описание изображения здесь

Я использую Xamarin.Forms 4.7 и VisualStudio 2019.

Что мне не хватает? Что-то в ресурсах? SwipeView не работает в ScrollView?

Ответы [ 2 ]

2 голосов
/ 27 июля 2020

Убедитесь, что вы добавили флаг для просмотра смахивания, поскольку он все еще экспериментальный. Фрагмент кода находится в файле App.xaml.cs для общего проекта Xamarin Forms.

    public partial class App : Application
    {           
        public App()
        {
            InitializeComponent();
            
            Device.SetFlags(new string[] { "CollectionView_Experimental", "SwipeView_Experimental" });
        }
   }
0 голосов
/ 04 августа 2020

Убрать FastRenderers_Experimental в MainActivity. или переместите FastRenderers_Experimental в последний.

global::Xamarin.Forms.Forms.SetFlags("SwipeView_Experimental");
global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental");
global::Xamarin.Forms.Forms.SetFlags("FastRenderers_Experimental");

вместо

global::Xamarin.Forms.Forms.SetFlags("FastRenderers_Experimental");
global::Xamarin.Forms.Forms.SetFlags("SwipeView_Experimental");
global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental");
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...