问题描述
Xamarin.Forms.ItemsView的类型初始值设定项引发了异常。单击按钮后。
The type initializer for 'Xamarin.Forms.ItemsView' threw an exception. After click button.
未处理的异常:
System.TypeInitializationException:Xamarin.Forms的类型初始值设定项。 ItemsView'引发了异常。
System.TypeInitializationException: The type initializer for 'Xamarin.Forms.ItemsView' threw an exception. occurred
`<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>`
推荐答案
此控件属于Xamarin.Forms 4.0。因此,您必须将表单版本更新为4.0才能测试此新功能。
This control belongs to Xamarin.Forms 4.0. So you have to update your forms version to 4.0 to test this new feature.
此外,您还必须添加
全局:: Xamarin.Forms.Forms.SetFlags( CollectionView_Experimental);
在您的MainActivity.cs和AppDelegate中启用此测试。
Moreover, you have to addglobal::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental");
in your MainActivity.cs and AppDelegate to enable this testing.
不幸的是,Carousel View只能在Android上使用:
Unfortunately, Carousel View can be only used on Android: https://github.com/pauldipietro/CollectionViewSample.
关注该博客以了解更多概念:
Follow this blog to learn more concepts: https://devblogs.microsoft.com/xamarin/xamarin-forms-4-0-feature-preview-an-entirely-new-point-of-collectionview/
这篇关于System.TypeInitializationException Xamarin CarouselView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!