System.TypeInitializationException Xamarin CarouselView

时间:2019-05-21 06:27:26

标签: xaml xamarin carousel

“ Xamarin.Forms.ItemsView”的类型初始值设定项引发了异常。点击按钮后。

未处理的异常:

System.TypeInitializationException:'Xamarin.Forms.ItemsView'的类型初始值设定项引发了异常。发生

`<CarouselView>
                    <CarouselView.ItemsSource>
                        <x:Array Type="{x:Type View}">
                            <ContentView>
                                <Image Source="yuzon.jpg"/>
                            </ContentView>
                            <ContentView>
                                <Image Source="yuzyirmi.jpg"/>
                            </ContentView>
                            <ContentView>
                                <Image Source="yuzkirks.jpg" />
                            </ContentView>
                            <Image Source="yuzelli.jpg" />
                            <ContentView>
                                <Image Source="yuzaltmis.jpg" />
                            </ContentView>
                            <ContentView>
                                <Image Source="ikiyuzyirmi.jpg"/>
                            </ContentView>
                            <ContentView>
                                <Image Source="ikiyuzkirkC.jpg" />
                            </ContentView>
                            <ContentView>
                                <Image Source="ikiyuzyetmis.jpg" />
                            </ContentView>
                            <Image Source="ucyuz.jpg"  />
                            <ContentView>
                                <Image Source="ucyuzF.jpg"  />
                            </ContentView>
                            <ContentView>
                                <Image Source="ucyuzon.jpg" />
                            </ContentView>
                            <ContentView>
                                <Image Source="ucyuzotuz.jpg"  />
                            </ContentView>
                            <ContentView>
                                <Image Source="ucyuzaltmis.jpg"  />
                            </ContentView>
                        </x:Array>
                    </CarouselView.ItemsSource>
                </CarouselView>` 

1 个答案:

答案 0 :(得分:2)

此控件属于Xamarin.Forms 4.0。因此,您必须将表单版本更新为4.0才能测试此新功能。

此外,您必须添加
global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental");在MainActivity.cs和AppDelegate中启用此测试。

很遗憾,“轮播视图”只能在Android https://github.com/pauldipietro/CollectionViewSample上使用。

关注此博客以了解更多概念:https://devblogs.microsoft.com/xamarin/xamarin-forms-4-0-feature-preview-an-entirely-new-point-of-collectionview/