System.TypeInitializationException Xamarin CarouselView

假如想象 提交于 2019-12-11 19:04:28

问题


The type initializer for 'Xamarin.Forms.ItemsView' threw an exception. After click button.

Unhandled Exception:

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>` 

回答1:


This control belongs to Xamarin.Forms 4.0. So you have to update your forms version to 4.0 to test this new feature.

Moreover, you have to add
global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental"); in your MainActivity.cs and AppDelegate to enable this testing.

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/



来源:https://stackoverflow.com/questions/56232284/system-typeinitializationexception-xamarin-carouselview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!